简体   繁体   English

使用 Terraform 创建实例类型 Fargate 的 EKS 节点组

[英]Create EKS node group of instance type Fargate with Terraform

With the eksctl cli one can create an EKS cluster of type Fargate which creates nodes of instance type "Fargate".使用 eksctl cli,可以创建 Fargate 类型的 EKS 集群,它创建实例类型为“Fargate”的节点。

How can the same be achieved with terraform?如何用 terraform 达到同样的效果? The cluster can be created with node groups, but instance type Fargate does not seem to exist (although eksctl creates it like that)可以使用节点组创建集群,但实例类型 Fargate 似乎不存在(尽管 eksctl 是这样创建的)

  node_groups = {
    eks_nodes = {
      desired_capacity = 3
      max_capacity     = 3
      min_capaicty     = 3

      instance_type = "Fargate"
    }
  }

Thanks!谢谢!

Have you tried to define a Fargate profile first?您是否尝试先定义Fargate 配置文件

You must define at least one Fargate profile that specifies which pods should use Fargate when they are launched.您必须至少定义一个 Fargate 配置文件,用于指定哪些 Pod 在启动时应使用 Fargate。 You also need to create a pod execution role this way the components running on the Fargate infrastructure need to make calls to AWS APIs on your behalf to do things like pull container images from Amazon ECR or route logs to other AWS services.您还需要创建一个pod 执行角色,这样运行在 Fargate 基础设施上的组件需要代表您调用 AWS API 来执行诸如从 Amazon ECR 中提取容器映像或将日志路由到其他 AWS 服务等操作。

A terraform code for aws eks fargage looks like the following: 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
  }
}

Make sure you're using the aws_eks_fargate_profile resource to create an eks fargate profile.确保您使用 aws_eks_fargate_profile 资源来创建 eks fargate 配置文件。

A terraform code for fargate pod execution role looks like the following: 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)
}

I suggest you check some awesome examples from awesome communities like Cloudposse .我建议您查看一些很棒的示例,这些示例来自很棒的社区,例如Cloudposse

I'll give you the complete example of fargate profile and eks-node-group , it seems the solution that you need to deploy at this moment.我会给你fargate 配置文件和 eks -node-group的完整示例,这似乎是你此时需要部署的解决方案。

Pd: Try to read how they made the modules, I think you'll reach your goal quickly. Pd:尝试阅读他们是如何制作模块的,我想你会很快达到你的目标。

I hope it may useful for you and other users.我希望它对您和其他用户有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM