Virtual Machine Scale Sets
Automatically scale identical VMs in or out based on demand, and configure health probes and load-balancing rules for high-availability applications.
Virtual Machine Scale Sets is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Problem Scale Sets Solve
Manually managing a fleet of identical VMs — adding servers during peak demand and removing them when demand drops — is tedious, error-prone, and slow. Virtual Machine Scale Sets (VMSS) automate this process by managing a group of identical, load-balanced VMs as a single resource. When demand increases, VMSS automatically adds new VM instances. When demand decreases, it removes instances. This eliminates the need for manual intervention and ensures you pay only for the capacity you need at any moment.
Creating a Scale Set
A scale set is defined by a VM profile (image, size, disk configuration, extensions) that every instance in the set shares. When you create a scale set, you specify the minimum and maximum instance counts and the initial capacity. All instances are created from the same image, ensuring consistency across the fleet. You can deploy a scale set across multiple availability zones, and Azure automatically distributes instances evenly across zones for high availability.
# Create a VM Scale Set across Zones 1, 2, and 3
az vmss create \
--resource-group myRG \
--name myScaleSet \
--image Ubuntu2204 \
--instance-count 2 \
--zones 1 2 3 \
--admin-username azureuser \
--generate-ssh-keysAutoscale Rules
VMSS autoscale rules define when to add or remove instances based on metrics. A typical rule reads: 'When average CPU utilisation exceeds 70% for 5 minutes, add 2 instances. When average CPU drops below 30% for 10 minutes, remove 1 instance.' You can also create rules based on custom metrics from Azure Monitor (e.g., queue depth, HTTP request rate) or on a schedule (e.g., scale to 20 instances every weekday morning and back to 5 overnight). Combining metric-based and schedule-based rules gives you precise control over capacity.
# Add autoscale rule: scale out when CPU > 70%
az monitor autoscale rule create \
--resource-group myRG \
--autoscale-name myScaleSetAutoscale \
--condition 'Percentage CPU > 70 avg 5m' \
--scale out 2Load Balancing with Scale Sets
Scale sets are almost always paired with a load balancer to distribute incoming requests across all healthy instances. Azure provides two options: Azure Load Balancer (Layer 4, TCP/UDP) for low-latency, high-throughput scenarios, and Azure Application Gateway (Layer 7, HTTP/HTTPS) for web applications that need URL-based routing, SSL termination, and WAF protection. The load balancer uses health probes to detect unhealthy instances and automatically stops routing traffic to them until they recover.
Health Probes and Instance Repair
VMSS can be configured with automatic instance repairs — if a health probe determines that an instance is unhealthy (e.g., the application is not responding on port 80), the scale set can automatically delete and replace that instance with a fresh, healthy one. This is configured via the automaticRepairsPolicy setting. A grace period (e.g., 10 minutes after launch) prevents instances from being replaced before they have had time to start their application and pass their first health check.
Uniform vs Flexible Orchestration
Azure VMSS supports two orchestration modes: Uniform mode — all instances are identical and managed as a group; ideal for stateless workloads like web servers and worker queues. Flexible mode — instances can have different sizes and configurations, and individual VMs can be managed independently while still benefiting from the scale set's zone distribution and health model. Flexible orchestration is better for heterogeneous workloads or when you need to replace specific instances without affecting others.
Rolling Upgrades for Zero Downtime
When you update the VM image or configuration in a scale set, you need to propagate the change to all instances. VMSS supports rolling upgrades, which update instances in small batches (e.g., 20% at a time) rather than all at once. This ensures the majority of instances remain in service while updates are applied. The rolling upgrade policy lets you configure the maximum batch size and the pause time between batches, giving you fine-grained control over the update velocity and minimising user impact.
Spot Instances in Scale Sets
VMSS can use Spot Instances (also called Azure Spot VMs) for dramatic cost savings — up to 90% off pay-as-you-go pricing — by running on unused Azure capacity. The trade-off is that Spot instances can be evicted with only 30 seconds notice when Azure needs the capacity back. For this reason, Spot instances in VMSS are suitable for fault-tolerant, stateless workloads such as batch processing jobs, media encoding, and CI/CD build agents that can tolerate interruption and resume from checkpoints.
Scaling Limits and Quotas
By default, a VMSS can contain up to 1,000 VM instances when using Azure Marketplace images, or up to 600 instances for custom images. Azure subscriptions also have per-region vCPU quotas that limit how many vCPUs you can use across all resources. If you need to scale beyond the default limits, you can request a quota increase through the Azure portal. Planning for these limits in advance is important for large-scale production deployments that may need to scale thousands of instances during peak events.
VMSS for Stateful Workloads
While VMSS is primarily designed for stateless workloads, it can also manage stateful applications using persistent OS disks. In this configuration, each instance retains its OS disk when deallocated during scale-in, so instance-specific state (such as unique configuration or session data) is preserved. This is used for applications like game servers where each instance has a distinct identity. However, for most stateful scenarios (databases, caches), dedicated Azure managed services like Azure SQL or Azure Cache for Redis are a better fit than VMs in a scale set.
Scale Set Monitoring and Diagnostics
Monitoring a VMSS requires visibility into both the scale set level (instance count over time, autoscale events) and the individual instance level (CPU, memory, disk, application logs). Azure Monitor collects platform metrics for the scale set automatically. For application-level metrics and logs, you install the Azure Monitor Agent extension on instances via the scale set VM profile, so every new instance automatically starts reporting to your Log Analytics workspace. This gives you unified observability across the entire fleet from a single dashboard.
Quick Check
Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.
Lesson Recap
In this lesson you learned: VM Scale Sets manage a group of identical, load-balanced VMs and autoscale based on metrics or schedules, health probes and automatic instance repair keep the fleet healthy without manual intervention, and rolling upgrades allow zero-downtime updates by replacing instances in small batches. Next up we explore Azure Virtual Desktop as a cloud-hosted desktop solution.
Frequently asked questions
Is the “Virtual Machine Scale Sets” lesson free?
Yes — the full text of “Virtual Machine Scale Sets” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Virtual Machine Scale Sets”?
Automatically scale identical VMs in or out based on demand, and configure health probes and load-balancing rules for high-availability applications. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Virtual Machine Scale Sets” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Azure Virtual Machines
- Virtual Machine Scale Sets
- Azure Virtual Desktop
- Choosing the Right Compute Service