启动服务部署实例

如何解决启动服务部署实例

我正在使用 Terraform 在 AWS 上部署 ECS EC2 集群。

我的管道正在从 docker-compose 创建一个新的任务定义,然后更新服务以使用此任务定义。 期望计数为 1,deployment_minimum_healthy_percent 为 100,deployment_maximum_percent 为 200。

预期行为是自动缩放组将启动一个新的 EC2 实例来部署新任务,然后杀死旧的。 发生的情况是我收到一条错误消息:“服务 X 无法放置任务,因为没有容器实例满足其所有要求。最接近的匹配容器实例的可用内存不足。”

没有创建实例,部署回滚。如何确保在部署我的服务时创建了额外的实例?

这是我的 Terraform 代码:​​

resource "aws_ecs_cluster" "main_cluster" {
  name        = var.application_name

  tags = {
    Environment = var.environment_name
  }
}

data "aws_ecs_task_definition" "main_td" {
  task_definition = var.application_name
}

resource "aws_ecs_service" "main_service" {
  name            = var.application_name
  cluster         = aws_ecs_cluster.main_cluster.id
  launch_type     = "EC2"
  scheduling_strategy = "REPLICA"
  task_definition = "${data.aws_ecs_task_definition.main_td.family}:${data.aws_ecs_task_definition.main_td.revision}"
  desired_count   = var.target_capacity
  deployment_minimum_healthy_percent = 100
  deployment_maximum_percent         = 200
  health_check_grace_period_seconds  = 10
  wait_for_steady_state = false
  force_new_deployment = true

  load_balancer {
    target_group_arn = aws_lb_target_group.main_tg.arn
    container_name   = var.container_name
    container_port   = var.container_port
  }

  ordered_placement_strategy {
    type = "binpack"
    field = "memory"
  }

  deployment_circuit_breaker {
    enable = true
    rollback = true
  }

  lifecycle {
    ignore_changes = [desired_count]
  }

  tags = {
    Environment = var.environment_name
  }
}

自动缩放组:

data "template_file" "user_data" {
  template = "${file("${path.module}/user_data.sh")}"

  vars = {
    ecs_cluster = "${aws_ecs_cluster.main_cluster.name}"
  }
}

resource "aws_launch_configuration" "main_lc" {
  name          = var.application_name
  image_id      = var.ami_id
  instance_type = var.instance_type
  associate_public_ip_address = true
  iam_instance_profile = "arn:aws:iam::812844034365:instance-profile/ecsInstanceRole"
  security_groups = ["${aws_security_group.main_sg.id}"]

  root_block_device {
    volume_size = "30"
    volume_type = "gp3"
  }

  user_data = "${data.template_file.user_data.rendered}"
}

resource "aws_autoscaling_policy" "main_asg_policy" {
  name                   = "${var.application_name}-cpu-scale-policy"
  policy_type            = "TargetTrackingScaling"
  autoscaling_group_name = aws_autoscaling_group.main_asg.name
  estimated_instance_warmup = 10

  target_tracking_configuration {
    predefined_metric_specification {
      predefined_metric_type = "ASGAverageCPUUtilization"
    }

    target_value = 40.0
  }
}

resource "aws_autoscaling_group" "main_asg" {
  name                 = var.application_name
  launch_configuration = aws_launch_configuration.main_lc.name
  min_size             = var.target_capacity
  max_size             = var.target_capacity * 2
  health_check_type    = "EC2"
  health_check_grace_period = 10
  default_cooldown     = 30
  desired_capacity     = var.target_capacity
  vpc_zone_identifier  = data.aws_subnet_ids.subnets.ids
  wait_for_capacity_timeout = "3m"

  instance_refresh {
    strategy = "Rolling"
    preferences {
      min_healthy_percentage = 100
    }
  }
}

模块在这里发布https://registry.terraform.io/modules/hboisgibault/ecs-cluster/aws/latest

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com(将#修改为@)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?