Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 18: Load Balancing

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.

  1. Open the Auto Scaling group.
  2. Attach the target group site-a-tg.
  3. Set the health check type to ELB.
  4. Set the health check grace period long enough for Nginx to start. 120 seconds is a fair lab value.
  5. Confirm desired capacity is 1 and one instance is healthy in site-a-tg.
  6. Run curl -s http://ALB-DNS/ and confirm you see a page.
  7. Raise desired capacity from 1 to 2.
  8. Watch the new instance appear in site-a-tg as initial.
  9. Do not stop the old instance yet.
  10. Wait until the new instance says healthy.
  11. Run curl -s http://ALB-DNS/ again.
  12. You should still see a page. Both instances can answer.
  13. Lower desired capacity from 2 to 1.
  14. Watch the extra instance move to draining.
  15. Wait until it is no longer a healthy target.
  16. You should see the remaining instance still healthy, and curl still returns a page.
  17. If you stop the only healthy instance before the new one is healthy, run curl during that gap.
  18. 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.