18.12 How this connects to scaling
Why Chapter 17 was missing this door
Chapter 17 changed desired capacity. A new instance with no target group is a computer nobody's browser can see. A target group with no health check will keep sending people to an instance that is still booting. Zero downtime means the new instance is healthy before the old one is removed.
What the Auto Scaling group changes
The group does not replace the load balancer. It registers and deregisters instances in the target group you attach. The balancer keeps one DNS name. The count of EC2 instances moves. In Chapter 17 the numbers were minimum 1, desired 1, then 2, maximum 3. Those are the same instances this chapter's group would list.
The health check type ELB means the group uses the target group's check, not only the EC2 status that says the virtual machine is running. Nginx can be stopped while EC2 still says running. ELB health catches that.
When an instance is removed, it enters draining. Existing requests can finish. New requests go to the instances that are still healthy. The deregistration delay is that wait. Then the instance is unused, and the group may terminate it.
How to add and remove an instance without dropping the page
Use lab-alb, site-a-tg, and the Auto Scaling group from Chapter 17 if you still have it. If the group is gone, do the register and deregister steps by hand. The order is the lesson.
- Open the Auto Scaling group.
- Attach the target group
site-a-tg. - Set the health check type to ELB.
- Set the health check grace period long enough for Nginx to start. 120 seconds is a fair lab value.
- Confirm desired capacity is 1 and one instance is healthy in
site-a-tg. - Run
curl -s http://ALB-DNS/and confirm you see a page. - Raise desired capacity from 1 to 2.
- Watch the new instance appear in
site-a-tgas initial. - Do not stop the old instance yet.
- Wait until the new instance says healthy.
- Run
curl -s http://ALB-DNS/again. - You should still see a page. Both instances can answer.
- Lower desired capacity from 2 to 1.
- Watch the extra instance move to draining.
- Wait until it is no longer a healthy target.
- You should see the remaining instance still healthy, and
curlstill returns a page. - If you stop the only healthy instance before the new one is healthy, run
curlduring that gap. - You should see 502. That gap is the downtime this order avoids.
Start instance A again if you stopped it earlier, so the later cleanup is tidy.