使用命令重启 fargate 任务

Restart fargate tasks with command

我有 ecs,它的服务有两个相同的负载均衡器任务。

并且此任务定义有两个容器来自 ECR 存储库

现在我想在更新 ECR 存储库后通过 aws cli 重新启动这两个任务。

我试试这个

aws ecs update-service --force-new-deployment --service myservice --cluster mycluster

但是,它启动了新的两个任务,但是旧的两个任务并没有停止,所以出现了四个任务。

如何重新启动两个任务,而不是添加两个任务。

新任务健康后,旧任务将停止。您还可以将最大百分比设置为 100,这样它会在启动新任务之前停止旧任务,并且 运行 个任务不会超过所需的任务数。

来自docs

maximumPercent

If a service is using the rolling update (ECS) deployment type, the maximumPercent parameter represents an upper limit on the number of your service's tasks that are allowed in the RUNNING or PENDING state during a deployment, as a percentage of the desiredCount (rounded down to the nearest integer). This parameter enables you to define the deployment batch size. For example, if your service is using the REPLICA service scheduler and has a desiredCount of four tasks and a maximumPercent value of 200%, the scheduler may start four new tasks before stopping the four older tasks (provided that the cluster resources required to do this are available). The default maximumPercent value for a service using the REPLICA service scheduler is 200%.