How do I deploy updated Docker images to Amazon ECS tasks?

前端 未结 12 1413
灰色年华
灰色年华 2021-01-29 22:00

What is the right approach to make my Amazon ECS tasks update their Docker images, once said images have been updated in the corresponding registry?

12条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-29 22:47

    There are two ways to do this.

    First, use AWS CodeDeploy. You can config Blue/Green deployment sections in ECS service definition. This includes a CodeDeployRoleForECS, another TargetGroup for switch, and a test Listener (optional). AWS ECS will create CodeDeploy application and deployment group and link these CodeDeploy resources with your ECS Cluster/Service and your ELB/TargetGroups for you. Then you can use CodeDeploy to initiate a deployment, in which you need to enter an AppSpec that specifies using what task/container to update what service. Here is where you specify your new task/container. Then, you will see new instances are spin up in the new TargetGroup and the old TargetGroup is disconnected to the ELB, and soon the old instances registered to the old TargetGroup will be terminated.

    This sounds very complicated. Actually, since/if you have enabled auto scaling on your ECS service, a simple way to do it is to just force a new deployment using console or cli, like a gentleman here pointed out:

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

    In this way you can still use the "rolling update" deployment type, and ECS will simply spin up new instances and drain the old ones with no downtime of your service if everything is OK. The bad side is you lose fine control on the deployment and you cannot roll back to previous version if there is an error and this will break the ongoing service. But this is a really simple way to go.

    BTW, don't forget to set proper numbers for Minimum healthy percent and Maximum percent, like 100 and 200.

提交回复
热议问题