您是否尝试过先定义Fargate profile?
您必须定义至少一个 Fargate 配置文件,以指定哪些 pod 在启动时应使用 Fargate。您还需要创建一个pod execution role,这样在 Fargate 基础设施上运行的组件需要代表您调用 AWS API 以执行诸如从 Amazon ECR 拉取容器映像或将日志路由到其他 AWS 服务等操作。
aws eks fargage 的 terraform 代码如下所示:
resource "aws_eks_fargate_profile" "default" {
cluster_name = var.cluster_name
fargate_profile_name = var.fargate_profile_name
pod_execution_role_arn = join("", aws_iam_role.default.arn)
subnet_ids = var.subnet_ids
tags = var.tags
selector {
namespace = var.kubernetes_namespace
labels = var.kubernetes_labels
}
}
确保您使用 aws_eks_fargate_profile 资源来创建 eks fargate 配置文件。
fargate pod 执行角色的 terraform 代码如下所示:
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["eks-fargate-pods.amazonaws.com"]
}
}
}
resource "aws_iam_role" "default" {
name = var.role_name
assume_role_policy = join("", data.aws_iam_policy_document.assume_role.json)
tags = var.tags
}
resource "aws_iam_role_policy_attachment" "amazon_eks_fargate_pod_execution_role_policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSFargatePodExecutionRolePolicy"
role = join("", aws_iam_role.default.name)
}
我建议你查看一些来自很棒的社区的很棒的例子,比如Cloudposse。
我给你完整的例子fargate profile和eks-node-group,看来你现在需要部署的解决方案。
Pd:尝试阅读他们是如何制作模块的,我认为您会很快达到目标。
我希望它对您和其他用户有用。