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

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

问题描述

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

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 将自动启动一个新的 EC2 实例,其中包含您的新 user_data,以替换终止的 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 任务和旧的 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天全站免登陆