⚖️ Azure Virtual Machine Scale Sets (VMSS)

📌 Overview

Azure Virtual Machine Scale Sets (VMSS) allow you to create and manage a group of identical, load-balanced VMs. The number of VM instances can automatically increase or decrease in response to demand or a defined schedule.


1. Scale Modes

↕️ Vertical Scaling (Scale Up/Down)

Changing the size of the virtual machine (e.g., from Standard_D2 to Standard_D4).

↔️ Horizontal Scaling (Scale Out/In)

Changing the number of instances (e.g., from 2 VMs to 5 VMs).


2. Orchestration Modes 🎻

Azure VMSS provides two ways to manage the instances:

🅰️ Uniform Orchestration (Review the "Classic" VMSS)

This is the standard mode familiar to most users.

🅱️ Flexible Orchestration (The New Standard)

Brings the best of Scale Sets and Availability Sets together.


3. How VMSS Works

  1. Golden Image: You provide a standard VM image (e.g., Ubuntu web server with Nginx installed) or a Custom Image (AMI equivalent).
  2. Configuration: You set the "Instance Count" or "Autoscale Rules".
  3. Load Balancer: A Load Balancer usually sits in front of the VMSS to distribute traffic to all healthy instances.

🧠 Autoscale Rules

You define when to add/remove VMs.

📐 Architecture Diagram

          (User)
             |
             v
   +-----------------------+
   |  Azure Load Balancer  |
   +-----------------------+
     /       |       \
    /        |        \
   v         v         v
+-----+   +-----+   +-----+
| VM1 |   | VM2 |   | VM3 |  <-- (VM Scale Set)
+-----+   +-----+   +-----+
    \        |        /
     \       |       /
      v      v      v
   +--------------------+
   | Azure SQL Database |
   +--------------------+

3. Availability & Fault Tolerance

VMSS automatically distributes instances across:

Note: An Availability Set is a similar concept but requires you to manage the VMs individually. VMSS manages them as a set.


4. 🛠️ Hands-on: Create VMSS with Azure CLI

Step 1: Create a Resource Group

az group create --name myResourceGroup --location eastus

Step 2: Create a VM Scale Set

This command creates a VMSS with 2 instances, a load balancer, and generates SSH keys automatically.

az vmss create \
  --resource-group myResourceGroup \
  --name myScaleSet \
  --image Ubuntu2204 \
  --upgrade-policy-mode automatic \
  --admin-username azureuser \
  --generate-ssh-keys

Step 3: View the Instances

Check the status of your running instances or list all resources in the group.

# List all resources (VMSS, LB, VNET, etc.)
az resource list --resource-group myResourceGroup --output table

# List specific VMSS instances
az vmss list-instances \
  --resource-group myResourceGroup \
  --name myScaleSet \
  --output table

Step 4: Manually Scale Out

Increase the instance count from default (2) to 5.

az vmss scale \
  --resource-group myResourceGroup \
  --name myScaleSet \
  --new-capacity 5

Step 5: Configure Autoscale (Optional)

Add a rule to scale out when CPU > 70%.

az monitor autoscale create \
  --resource-group myResourceGroup \
  --resource myScaleSet \
  --resource-type Microsoft.Compute/virtualMachineScaleSets \
  --name myAutoscale \
  --min-count 2 \
  --max-count 10 \
  --count 2

Step 6: Clean Up

Don't forget to delete resources to avoid costs!

az group delete --name myResourceGroup --yes --no-wait

💡 Exam Tips for AZ-900