0
0

More than 3 years have passed since last update.

AutoScalingのスケールイン対象をコントロールする場合に注意すべきRebalancing

Posted at

背景

何かしらの解析サーバとしてEC2を利用しAutoScaling構成をとる場合、解析が終了したものから順次スケールインさせたい時がある。そのままだと一番古いものなどの条件でしか対応できない。解決策の一つとしてterminateを各EC2自身に行わせる場合にはAZの再分散に注意する必要がある。

わかったこと

Auto ScalingはRebalancing(再分散)といってAZの偏りを修正するための機能がある。
https://docs.aws.amazon.com/autoscaling/ec2/userguide/auto-scaling-benefits.html

suspend-processesコマンドを打ってやるとRebalancingを停止することができる。
(その他、オプション指定により種々の機能を選択することが可)
https://docs.aws.amazon.com/cli/latest/reference/autoscaling/suspend-processes.html

やってみた

9個のインスタンスを持つAuto Scaling Groupを用意し、3つのAZに3インスタンスずつ用意。
まずは何もしない状態で、AZがアンバランスになるように3つのインスタンスを以下のコマンドでterminate。
このコマンドは、インスタンスをterminateすると同時にdesired capacityをデクリメントしてくれる。

$ aws autoscaling terminate-instance-in-auto-scaling-group --instance-id INSTANCE_ID --should-decrement-desired-capacity

image.png

数秒のうちに新規のインスタンスが立ち上がり、その後1つのインスタンスがterminateされることでアンバランスなAZが修正された。

image.png

ここで、再度9台に戻してから今回知ったコマンドを打ってから同じことをリトライ。
確かにAZの偏りは維持された。

$ aws autoscaling suspend-processes --auto-scaling-group-name ASG_NAME --scaling-processes AZRebalance

この設定状態はAuto Scalingの詳細の欄の停止したプロセスから見ることができる。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0