VM scale sets and load balancing

Microsoft Azure · Practical · 13 min

Scale sets are how IaaS workloads get elasticity and high availability.

A virtual machine scale set manages a group of VMs created from one configuration. Two orchestration modes exist:

  • Flexible (the default and recommendation): instances are regular VMs you can mix sizes in, spread across zones and fault domains, and manage with normal VM APIs.
  • Uniform: identical instances managed only through the scale set; the older model, still used by some services.

Put a Standard Load Balancer (layer 4, TCP/UDP) in front: a frontend IP, a backend pool of the instances, a health probe and load-balancing rules. Only instances passing the probe receive traffic. For HTTP features like path routing, TLS termination and WAF, use Application Gateway (regional, layer 7) or Front Door (global).

Autoscale adds and removes instances based on metric rules (average CPU above 70% for 10 minutes: add 2) or schedules, with minimum, maximum and default counts. Scale-in must be safe, so keep instances stateless and drain gracefully.

Keep instances healthy with the Application Health extension plus automatic instance repairs, and roll out image changes with a rolling upgrade policy. Spread instances across availability zones (--zones 1 2 3) so a zone failure removes only a third of capacity.

Example

az vmss create -g rg-web -n vmss-web \
  --orchestration-mode Flexible --image Ubuntu2404 --vm-sku Standard_D2s_v5 \
  --instance-count 3 --zones 1 2 3 \
  --admin-username azureuser --generate-ssh-keys \
  --custom-data cloud-init.yaml --lb-sku Standard

az monitor autoscale create -g rg-web -n as-web \
  --resource vmss-web --resource-type Microsoft.Compute/virtualMachineScaleSets \
  --min-count 3 --max-count 12 --count 3

az monitor autoscale rule create -g rg-web --autoscale-name as-web \
  --condition "Percentage CPU > 70 avg 10m" --scale out 2
az monitor autoscale rule create -g rg-web --autoscale-name as-web \
  --condition "Percentage CPU < 30 avg 15m" --scale in 1

Remember

  • Flexible orchestration is the default for new scale sets
  • Load Balancer = L4; Application Gateway / Front Door = L7
  • Autoscale needs both scale-out and scale-in rules
  • Spread across zones and enable automatic repairs

Watch out for

  • Adding only a scale-out rule, so the set grows under load and never shrinks.

Check yourself

  1. Which component decides whether an instance receives traffic from a Standard Load Balancer?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/overview