简体   繁体   English

容量提供程序实例未添加到集群

[英]Capacity provider instances not being added to cluster

I'm new to AWS and I'm trying to provision an ECS cluster with a capacity provider via Terraform. My plan executes without errors currently, and I can see that the capacity provider creates my instances, but those instances are not being registered with the cluster, even though the provider can be seen in the cluster's edit page in the web console.我是 AWS 的新手,我正在尝试通过 Terraform 使用容量提供程序配置 ECS 集群。我的计划目前执行无误,我可以看到容量提供程序创建了我的实例,但这些实例没有注册集群,即使可以在 web 控制台的集群编辑页面中看到提供程序。

Here is my config for the cluster:这是我的集群配置:

resource "aws_ecs_cluster" "cluster" {
  name = "main"

  depends_on = [
    null_resource.iam_wait
  ]
}

data "aws_ami" "amazon_linux_2" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn2-ami-ecs-hvm-*-x86_64-ebs"]
  }
}

resource "aws_launch_configuration" "cluster" {
  name = "cluster-${aws_ecs_cluster.cluster.name}"
  image_id = data.aws_ami.amazon_linux_2.image_id
  instance_type = "t2.small"

  security_groups = [module.vpc.default_security_group_id]
  iam_instance_profile = aws_iam_instance_profile.cluster.name
}

resource "aws_autoscaling_group" "cluster" {
  name = aws_ecs_cluster.cluster.name
  launch_configuration = aws_launch_configuration.cluster.name
  vpc_zone_identifier = module.vpc.private_subnets

  min_size = 3
  max_size = 3
  desired_capacity = 3

  tag {
    key = "ClusterName"
    value = aws_ecs_cluster.cluster.name
    propagate_at_launch = true
  }

  tag {
    key = "AmazonECSManaged"
    value = ""
    propagate_at_launch = true
  }
}

resource "aws_ecs_capacity_provider" "cluster" {
  name = aws_ecs_cluster.cluster.name

  auto_scaling_group_provider {
    auto_scaling_group_arn = aws_autoscaling_group.cluster.arn

    managed_scaling {
      status = "ENABLED"
      maximum_scaling_step_size = 1
      minimum_scaling_step_size = 1
      target_capacity = 3
    }
  }
}

resource "aws_ecs_cluster_capacity_providers" "cluster" {
  cluster_name = aws_ecs_cluster.cluster.name

  capacity_providers = [aws_ecs_capacity_provider.cluster.name]

  default_capacity_provider_strategy {
    base = 1
    weight = 100
    capacity_provider = aws_ecs_capacity_provider.cluster.name
  }
}

The instance profile role has this policy:实例配置文件角色具有此策略:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeTags",
        "ecs:CreateCluster",
        "ecs:DeregisterContainerInstance",
        "ecs:DiscoverPollEndpoint",
        "ecs:Poll",
        "ecs:RegisterContainerInstance",
        "ecs:StartTelemetrySession",
        "ecs:Submit*",
        "ecr:GetAuthorizationToken",
        "ecr:GetDownloadUrlForLayer",
        "ecr:BatchGetImage",
        "ecr:BatchCheckLayerAvailability",
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "*"
    }
  ]
}

I've read that this can happen if the instances do not have the proper roles, but as far as I can tell I've set up my roles correctly.我读过,如果实例没有适当的角色,就会发生这种情况,但据我所知,我已经正确设置了我的角色。 I'm not getting any visible permission errors that I can find.我没有收到任何我能找到的可见权限错误。

Another strange thing I've seen is that if another cluster named "default" exists, then the instances will register themselves to that cluster, even though the capacity provider is still attached to the other cluster.我看到的另一件奇怪的事情是,如果存在另一个名为“default”的集群,那么实例将自己注册到该集群,即使容量提供程序仍然连接到另一个集群。

Figured it out!弄清楚了! I just had to set user_data like below in my launch configuration.我只需要在我的启动配置中像下面这样设置user_data

resource "aws_launch_configuration" "cluster" {
  name = "cluster-${aws_ecs_cluster.cluster.name}"
  image_id = data.aws_ami.amazon_linux_2.image_id
  instance_type = "t2.small"

  security_groups = [module.vpc.default_security_group_id]
  iam_instance_profile = aws_iam_instance_profile.cluster.name

  user_data = "#!/bin/bash\necho ECS_CLUSTER=${aws_ecs_cluster.cluster.name} >> /etc/ecs/ecs.config"
}

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

相关问题 AWS ECS 集群容量提供程序 - AWS ECS cluster Capacity Provider 将容量提供程序附加到在不同 Cloudformation 堆栈中创建的 ECS 集群 - Attach Capacity Provider to a ECS Cluster created in different Cloudformation stacks 创建容量提供程序时出现 AWS ECS 错误 - AWS ECS Error When Creating Capacity Provider 可以使用 Terraform 更新 AWS ECS 容量提供程序吗? - Can AWS ECS capacity provider be updated using Terraform? 将容量提供程序与 ECS 一起使用时,需要多长时间才能删除实例? - How long will it take for an instance to be removed when using capacity provider with ECS? 关于 AWS EC2 实例中的 Kubernetes 集群 - About Kubernetes cluster in AWS EC2 instances 从多个数据块实例收集集群信息 - Gather cluster info from multiple databricks instances 如何识别 EKS 集群是否正在使用外部秘密存储提供程序 - how to Identify if an EKS cluster is using an external secret storage provider 使用 terraform 创建 aks 集群时出现 Hashicorp 提供程序错误 - Getting Hashicorp Provider Error while creating aks cluster using terraform 正常的 Aurora serverless v2 mysql 实例总是使用超过 90% 的 cpu 容量吗? - Is it normal Aurora serverless v2 mysql instances always using over 90% of cpu capacity?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM