Skip to main content
Cloud basicsLesson 4 of 17

Auto-Scaling VMs (Auto Scaling Groups)

An online store runs on two virtual machines. An auto scaling group adds VMs automatically when traffic spikes, replaces broken ones, and removes some when things quiet down. HPA, which does the same for Pods, is covered in Scaling with Load (HPA). Here we look one layer below: the number of servers (VMs) going up and down.

Average CPU40%
Desired (min 2 · max 4)2
VMs serving2
Auto scaling groupUserShopping requestsLoad balancerTo registered VMsMonitoringAlarm at CPU 70%Scaling groupKeeps desired countLaunch templateImage · typeVM 1Virtual machineVM 2Virtual machineVM 3New VMVM 4Replacement
RequestResponse / reportWatchAppears in a later step

What you will learn

  • What the launch template and min/desired/max counts do
  • How a metric alarm changes the desired count
  • A new VM serves only after passing health checks
  • The group replaces broken VMs on its own
  • Why scale-in uses a cooldown

Auto scaling group names (AWS · Azure · GCP)​

ConceptAWSAzureGCP
Auto-scaling group of VMsAuto Scaling groupVirtual Machine Scale SetsManaged instance group (MIG)
VM blueprintLaunch templateScale set VM modelInstance template
Replace VMs failing health checksHealth check-based replacementAutomatic instance repairsAutohealing

Try it yourself​

aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names <asg> --query 'AutoScalingGroups[].[MinSize,DesiredCapacity,MaxSize]' # min/desired/max (AWS example)
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names <asg> --query 'AutoScalingGroups[].Instances[].[InstanceId,LifecycleState,HealthStatus]' --output table # VMs and their health
aws ec2 describe-launch-template-versions --launch-template-id <lt-id> --versions '$Latest' # The launch template blueprint
aws autoscaling describe-policies --auto-scaling-group-name <asg> # Scaling policies tied to alarms
aws autoscaling describe-scaling-activities --auto-scaling-group-name <asg> --max-items 5 # Recent scale out/in and replacements

Check yourself

  1. The CPU alarm fires and desired goes from 2 to 3, but for several minutes only 2 VMs take requests. Why?
  2. VM 1 fails health checks repeatedly. What does the auto scaling group do?
  3. Why does the group wait out a cooldown right after scaling?

Further reading: Amazon EC2 Auto Scaling (AWS) · Node Autoscaling (Kubernetes docs) · Scaling with Load (HPA)