【发布时间】:2023-02-01 16:04:09
【问题描述】:
对于我在 ECS Fargate 中运行的高流量容器化应用程序,新容器需要缓慢启动,以避免启动后立即出现内存不足的情况。当所有容器同时被替换时,这在更新服务操作期间尤其重要。
我怎样才能让它与 ECS Fargate 和 ALB 一起工作,确保旧容器一直存在,直到新容器的 slow_start 期结束?
这是我当前的地形设置。我启用了slow_start,但在更新服务期间,旧容器过早停止,因此新容器立即获得全部流量。
resource "aws_alb_target_group" "my_target_group" {
name = "my_service"
port = 8080
protocol = "HTTP"
vpc_id = data.aws_vpc.active.id
target_type = "ip"
slow_start = 120
health_check {
enabled = true
port = 8080
path = "/healthCheck"
unhealthy_threshold = 2
healthy_threshold = 2
}
}
resource "aws_ecs_service" "my_service" {
name = "my_service"
cluster = aws_ecs_cluster.my_services.id
task_definition = aws_ecs_task_definition.my_services.arn
launch_type = "FARGATE"
desired_count = var.desired_count
deployment_maximum_percent = 400
deployment_minimum_healthy_percent = 100
enable_execute_command = true
wait_for_steady_state = true
network_configuration {
subnets = data.aws_subnets.private.ids
security_groups = [aws_security_group.my_service_container.id]
}
load_balancer {
container_name = "my-service"
container_port = 8080
target_group_arn = aws_alb_target_group.my_target_group.arn
}
lifecycle {
create_before_destroy = true
ignore_changes = [desired_count]
}
}
【问题讨论】:
-
你可以试试stopTimeout。
-
嗯,我认为 stopTimeout 仅用于拒绝关闭并需要强行杀死的容器。这里不是这种情况,我的应用程序干净地关闭了。
-
您是否尝试过在
deregistration_delay选项中设置更大的值? -
文档说默认的 deregistration_delay 是 300 秒,但是我的容器在大约 40 秒后停止,只要新容器启动并运行。此外,我的请求的响应时间非常短,约为 10-30 毫秒,因此我认为注销不是这里的主要问题。我的感觉是 ECS 部署不知道 ALB slow_start 特性,所以它在启动完成之前终止了容器。
-
你的 desired_count 是多少?我想知道问题是否是 min% 太低,导致 ECS 部署过早终止“旧”任务——这只留下“新”任务,因此它们会立即退出慢启动模式?
标签: amazon-web-services terraform amazon-ecs terraform-provider-aws aws-application-load-balancer