11

I wonder if there is a simple way or best practices on how to ensure all instances within an AutoScaling group have been launched with the current launch-configuration of that AutoScaling group.

To give an example, imagine an auto-scaling group called www-asg with 4 desired instances running webservers behind an ELB. I want to change the AMI or the userdata used to start instances of this auto-scaling group. So I create a new launch configuration www-cfg-v2 and update www-asg to use that.

# create new launch config
as-create-launch-config www-cfg-v2 \
    --image-id 'ami-xxxxxxxx' --instance-type m1.small \
    --group web,asg-www --user-data "..."

# update my asg to use new config
as-update-auto-scaling-group www-asg --launch-configuration www-cfg-v2

By now all 4 running instances still use the old launch configuration. I wonder if there is a simple way of replacing all running instances with new instances to enforce the new configuration, but always ensure that the minimum of instances is kept running.

My current way of achieving this is as follows..

  1. save list of current running instances for given autoscaling group
  2. temporarily increase the number of desired instances +1
  3. wait for the new instance to be available
  4. terminate one instance from the list via

    as-terminate-instance-in-auto-scaling-group i-XXXX \
        --no-decrement-desired-capacity --force
    
  5. wait for the replacement instance to be available

  6. if more than 1 instance is left repeat with 4.
  7. terminate last instance from the list via

    as-terminate-instance-in-auto-scaling-group i-XXXX \
        --decrement-desired-capacity --force
    
  8. done, all instances should now run with same launch config

I have mostly automated this procedure but I feel there must be some better way of achieving the same goal. Anyone knows a better more efficient way?

mathias

Also posted this question in the official AWS EC2 Forum.

4

2 回答 2

1

我知道的老问题,但我想我会分享我的方法。

我更改了 ASG 的启动配置,然后启动与当前在 ASG 中相同数量的实例,因为它们变得可用(自动测试)它们附加到 ASG。添加机器后,我们的部署系统会更新我们的清漆负载均衡器以使用新实例,而旧实例将被终止。

以上所有操作都是自动化的,全站点规模切换大约需要 5 分钟,具体取决于启动时间。

如果您想知道,我们使用 SNS 来处理在添加或删除实例时更新清漆,或者在我们的负载均衡器扩展(几乎从未发生)的情况下,部署系统将更新我们的 route53 配置。

我认为这几乎涵盖了所有内容

于 2014-05-27T13:58:30.283 回答
1

这并没有太大的不同,但您可以:

  1. 创建新的信用证
  2. 使用新的 LC 创建新的 ASG
  3. 缩小旧的 ASG
  4. 删除旧的 asg 和 LC

我以这种方式进行部署,根据我的经验,从一个 ASG 滚动到另一个,而不必来回跳跃。但正如我所指出的,这并不是一个巨大的差异。

可能值得一看: https ://github.com/Netflix/asgard ,这是一个用于管理自动缩放组的 Netflix OSS 工具。我最终没有使用它,但它仍然很有趣。

于 2013-10-08T14:02:20.237 回答