除了设置ASG整体控制EC2的扩容与缩容外,在实例层面也有一些单独的操作,比如:
detach
操作)Standby
,不让它接收线上流量;再把它设置成InService(scale-in protection
)我们将一一介绍这三种操作
可以将ASG中InService
状态的某台机器从中分离出来,通常用于:
在进行detach操作时,要注意:
minimum capacity
,则操作会失败desired capacity
,ASG会重新拉起新的机器deregistration delay
完成。在ASG的Instance management
页面,将某台EC2进行Detach:
点击Detach instance
:
发现报错,因为当前minimum capacity = 2
, Detach这台机器后会使ASG机器数量小于这个值:
在Detach时,有一个操作是先补一台EC2到ASG中,再进行Detach操作:
重新进行Detach操作,此时新加一台机器和Detach原来的机器并行进行:
Detach操作是将某台机器从ASG中移除;Set to standby
是临时设置,机器还存在于ASG中,只是不接收线上流量,然后随时还能将它设置成InService
状态。
You can put an instance that is in the InService
state into the Standby
state, update or troubleshoot the instance, and then return the instance to service. Instances that are on standby are still part of the Auto Scaling group, but they do not actively handle load balancer traffic.
This feature helps you stop and start the instances or reboot them without worrying about Amazon EC2 Auto Scaling terminating the instances as part of its health checks or during scale-in events.
For example, you can change the Amazon Machine Image (AMI) for an Auto Scaling group at any time by changing the launch template or launch configuration. Any subsequent instances that the Auto Scaling group launches use this AMI. However, the Auto Scaling group does not update the instances that are currently in service. You can terminate these instances and let Amazon EC2 Auto Scaling replace them, or use the instance refresh feature to terminate and replace the instances. Or, you can put the instances on standby, update the software, and then put the instances back in service.
Detaching instances from an Auto Scaling group is similar to putting instances on standby. Detaching instances might be useful if you want to manage the instances like standalone EC2 instances and possibly terminate them. For more information, see Detach EC2 instances from your Auto Scaling group .
When you put instances on standby, your Auto Scaling group can become unbalanced between Availability Zones. Amazon EC2 Auto Scaling compensates by rebalancing the Availability Zones unless you suspend the AZRebalance
process. For more information, see Suspend and resume a process for an Auto Scaling group
.
The standby state works as follows to help you temporarily remove an instance from your Auto Scaling group:
Amazon EC2 Auto Scaling does not perform health checks on instances that are in a standby state. While the instance is in a standby state, its health status reflects the status that it had before you put it on standby. Amazon EC2 Auto Scaling does not perform a health check on the instance until you put it back in service.
For example, if you put a healthy instance on standby and then terminate it, Amazon EC2 Auto Scaling continues to report the instance as healthy. If you attempt to put a terminated instance that was on standby back in service, Amazon EC2 Auto Scaling performs a health check on the instance, determines that it is terminating and unhealthy, and launches a replacement instance. For an introduction to health checks, see Health checks for Auto Scaling instances .
如果我们想查某台机器的问题,先把它从ASG中剥离,查完之后将其再恢复到ASG中。此时可以使用standby方式:
剥离的同时,可以同时新建一台实例补上去:
状态稳定后:
可以将备用的机器重新恢复成可用:
如果某台机器特别重要,不想让ASG将其terminate,可以设置实例保护:
极端情况下,将所有机器都设置实例保护:
此时更改所需要机器数量,不会影响到这两台被保护的机器: