Virtual Machine Scale Sets

Virtual Machine Scale Sets (VMSS) allow you to create and manage a group of load-balanced virtual machines. The number of VM instances can automatically increase or decrease based on demand or a defined schedule. This provides high availability for your applications, and allows the application to scale efficiently as load changes.

Key Features

  • Automatic Scaling: Configure rules to automatically scale in or out based on metrics like CPU utilization, network traffic, or a custom metric.
  • Instance Health: Monitor the health of your VM instances and automatically replace unhealthy instances.
  • Orchestration Modes: Choose between Uniform and Flexible orchestration modes to manage your VM instances.
  • Rolling Upgrades: Update VM instances with minimal downtime during application upgrades.
  • Custom Images: Deploy VMSS from custom images for specialized application requirements.

Getting Started

Create a VM Scale Set

You can create a VM scale set using the Azure portal, Azure CLI, Azure PowerShell, or ARM templates.

Using Azure CLI

The following command creates a basic VM scale set:


az vmss create \
  --resource-group MyResourceGroup \
  --name MyVmss \
  --image UbuntuLTS \
  --upgrade-policy-mode automatic \
  --admin-username azureuser \
  --generate-ssh-keys
                

Configure Scaling

To configure automatic scaling, you'll typically define Scale Out and Scale In rules. For example, to scale out when CPU utilization exceeds 70% and scale in when it drops below 30%:


# Scale out rule
az monitor autoscale create \
  --resource-group MyResourceGroup \
  --name MyVmssAutoscale \
  --child-resource MyVmss \
  --min-count 2 \
  --max-count 10 \
  --count 3 \
  --scale-out 1 \
  --scale-rule-metric-name PercentageCPU \
  --scale-rule-metric-statistic Average \
  --scale-rule-metric-threshold 70 \
  --scale-rule-time-scale 10 \
  --scale-rule-time-unit Minute

# Scale in rule (similar structure, adjust threshold and direction)
az monitor autoscale create \
  --resource-group MyResourceGroup \
  --name MyVmssAutoscale \
  --child-resource MyVmss \
  --min-count 2 \
  --max-count 10 \
  --count 3 \
  --scale-in 1 \
  --scale-rule-metric-name PercentageCPU \
  --scale-rule-metric-statistic Average \
  --scale-rule-metric-threshold 30 \
  --scale-rule-time-scale 10 \
  --scale-rule-time-unit Minute
                

Scenarios

Web Application Hosting

VMSS is ideal for hosting stateless web applications. By integrating with an Azure Load Balancer or Application Gateway, you can distribute incoming traffic across your VM instances, ensuring high availability and performance.

Batch Processing

For batch processing workloads, VMSS can be scaled up to handle large jobs and then scaled down to save costs when the workload is complete. You can use Azure Batch to manage and orchestrate these workloads.

Best Practices

  • Use custom images for faster provisioning times.
  • Leverage Instance Health for automatic remediation.
  • Configure scaling rules based on relevant application metrics.
  • Consider using Azure Load Balancer or Application Gateway for traffic distribution.
  • Implement a rolling upgrade policy to minimize downtime during updates.
Note: Flexible orchestration mode provides per-instance control and is suitable for workloads that require individual VM management, while Uniform orchestration mode is optimized for identical VM instances.
Tip: For predictable scaling needs, consider using scheduled scaling actions in addition to metric-based scaling.

Learn More