如何强制AWS ECS将容器迁移到另一个ASG? [英] How to force AWS ECS migrate containers to another ASG?

查看:222
本文介绍了如何强制AWS ECS将容器迁移到另一个ASG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用user_data对ECS中用于运行容器的主机进行初始配置.我希望能够告诉AWS ECS在更新user_data之后将容器迁移到新创建的主机.我该怎么办?

I'm using user_data to do initial configuration of the hosts used in ECS to run containers. I want to be able to tell AWS ECS to migrate containers to a newly created hosts once I update user_data. How can I do that?

我正在使用Terraform进行AWS基础设施部署.

I'm using Terraform for AWS infrastructure deployments.

推荐答案

我不认为ECS具有内置的方法来执行此操作.结果,它通常需要相当繁琐的&手动过程(尽管可以编写脚本).有几种不同的方法可以做到这一点,但这通常是最简单的方法:

I don't think ECS has a built-in way to do this. As a result, it usually requires a fairly tedious & manual process (albeit one that could be scripted). There are a few different ways to do it, but this is typically the simplest one:

  1. user_data进行更改.
  2. 运行terraform apply.
  3. 对于您的ASG中具有旧版user_data的每个EC2实例:
  1. Make your change to user_data.
  2. Run terraform apply.
  3. For each EC2 Instance in your ASG that has the old user_data:
  1. 终止该EC2实例.您可以通过AWS CLI或EC2 Web控制台执行此操作.
  2. 过一会儿,ASG将使用您的新user_data自动启动一个新的EC2实例,以替换终止的EC2实例.
  3. 过一会儿,ECS将自动启动碰巧在终止的EC2实例上运行的任何ECS任务的新副本.
  1. Terminate that EC2 Instance. You can do this via the AWS CLI or via the EC2 web console.
  2. After a little while, the ASG will automatically launch a new EC2 Instance, with your new user_data, to replace the terminated EC2 Instance.
  3. After a little while, ECS will automatically launch new copies of any ECS Tasks that happened to be running on the terminated EC2 Instance.

完成此过程后,ASG中的所有实例将运行新的user_data.请注意,只要您的ECS任务的停机时间为零,就可以完成此操作,

Once you have gone through this process, all of the Instances in the ASG will be running the new user_data. Note that this can be done with zero-downtime for your ECS Tasks as long as:

  1. 每个ECS任务至少有2个副本,每个副本在您的ASG中的单独EC2实例上.
  2. 您在终止EC2实例之间等待了足够的时间,以重新启动ECS任务.

如果您不能满足这些要求,则可能会有一些停机时间,或者您可能需要采用更复杂的选择,其中涉及使ASG的大小增加一倍,等待新的EC2实例(它将具有新的user_data)部署在ASG中,将ECS任务的数量加倍,等待这些新的ECS任务部署(它们通常将部署到新的EC2实例上),然后再将每个ECS任务减少一半(理论上是旧的ECS)任务和旧的EC2实例将终止,仅保留新的实例).

If you can't meet those requirements, then you may have some downtime, or you may need to pursue a messier option that involves doubling the size of the ASG, waiting for the new EC2 Instances (which will have the new user_data) to deploy in the ASG, doubling the number of ECS Tasks, waiting for those new ECS Tasks to deploy (they will typically deploy onto the new EC2 Instances), and then reducing each by half again (in theory, the old ECS Tasks and old EC2 Instances will be terminated, leaving just the new ones behind).

这篇关于如何强制AWS ECS将容器迁移到另一个ASG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆