Lesson 7 / 25
Virtual Machines and Scale Sets
Size, place and scale Azure VMs for availability.
Infrastructure as a service
An Azure Virtual Machine gives you a full operating system, so you control patches, runtimes and agents: maximum flexibility, maximum responsibility. A VM size (for example Standard_D2s_v5) fixes vCPU, memory and disk throughput; the B-series is burstable and cheap for low average load. Each VM has an OS disk and optional data disks backed by managed disks (Standard HDD, Standard SSD, Premium SSD, Premium SSD v2, Ultra). For availability, place VMs across availability zones, or at least in an availability set, which spreads them over fault and update domains inside one datacentre. Virtual Machine Scale Sets manage a group of identical VMs and add or remove instances with autoscale rules. Spot VMs use spare capacity at a large discount but can be evicted, which suits batch jobs, not your login server.
Scale out across zones
A scale set places identical instances in different zones behind a load balancer, and autoscale changes the count.
Creating a zone-redundant scale set
A small Linux scale set across three zones with a CPU-based autoscale rule.
az vmss create -g rg-shop-dev-cin -n vmss-web \
--image Ubuntu2204 --vm-sku Standard_B2s \
--instance-count 2 --zones 1 2 3 \
--admin-username azureuser --generate-ssh-keys
az monitor autoscale create -g rg-shop-dev-cin \
--resource vmss-web --resource-type Microsoft.Compute/virtualMachineScaleSets \
--name web-autoscale --min-count 2 --max-count 6 --count 2
az monitor autoscale rule create -g rg-shop-dev-cin --autoscale-name web-autoscale \
--condition "Percentage CPU > 70 avg 5m" --scale out 1Stopped is not deallocated
Shutting a VM down from inside the OS leaves it Stopped and you still pay for compute. Stop it from Azure (az vm deallocate) to release the hardware. Disks and public IPs are billed either way.
Quick check: Which option is cheapest for an interruptible overnight batch job?
- Spot VMs
- Premium SSD v2 disks
- A single VM in an availability set
- Ultra disks
Answer
Spot VMs — Spot VMs are heavily discounted but can be evicted, which a restartable batch job tolerates.