Skip to content

Lab 08: Run VMs across zones and scale them

At a glance

  • Time: about 60 minutes
  • Region: one of Australia East, Malaysia West or Southeast Asia 3 (see below)
  • You create: 2 small Ubuntu VMs, 1 data disk and 1 virtual machine scale set with 2 instances
  • Cost: VMs and scale set instances bill while they exist. Delete everything at the end.

What you will learn

  • How to deploy VMs into availability zones.
  • How to resize a VM and manage its disks.
  • How to create and autoscale a virtual machine scale set.

What is different in this environment

  • Ubuntu VMs instead of Windows, in one of the three regions below, using only the VM sizes allowed in that region.
  • Disks are Standard HDD or Standard SSD only. Premium disks are blocked.
  • You resize to another allowed size in your region, not a larger one.
  • A scale set may have at most 4 instances, and an autoscale maximum of 4, not 10.
  • Scale sets must use Uniform orchestration.
  • The lab has four tasks. Creating VMs with PowerShell and the CLI is not part of it.
Diagram: VMs lab-vm1 in zone 1 and lab-vm2 in zone 2, a data disk moved between them, and a Uniform scale set across zones 1, 2 and 3 with autoscale between 2 and 4 instances.
Two VMs in different zones, a data disk you move, and a scale set across three zones with autoscale. Select the diagram to open it full size.

Before you start

  • You are signed in to the lab directory (Getting started).
  • Your lab resource group is rg-CLOUD-LAB-GRP-N. Replace N with your group number.
  • Delete the resources from Lab 07. Each group may hold only 2 VMs and 3 disks besides scale sets.
  • Have the VM password from your trainer ready (for user azureuser).

Choose your region and VM size

Your trainer tells you which region to use. Use the same region for every resource in this lab.

Region Allowed VM sizes (use these)
Southeast Asia 3 Standard_B1s, Standard_B1ms, Standard_B2s, Standard_DS1_v2, Standard_DS2_v2
Australia East Standard_D2als_v6, Standard_D2as_v6, Standard_D2als_v7, Standard_D2as_v7
Malaysia West Standard_D2als_v6, Standard_D2s_v4
  • In this lab, size A is the first size in your region's list, and size B is the second.
  • Southeast Asia 3 example: size A is Standard_B1s, size B is Standard_B2s.
  • A size that isn't on your region's list is blocked with [LAB-P03A-VM-SIZE]. The same list applies to scale sets ([LAB-P15A-VMSS-SIZE]).
  • Southeast Asia 3 and Malaysia West allow 10 vCPUs in total for the subscription. Most of these sizes have 2 vCPUs, so the 2 VMs and the 2 scale set instances use 8 of them. Don't add more. (Standard_B1s has 1 vCPU.)

Task 1: Deploy two VMs in different availability zones

An availability zone is a separate data center in the same region. Two VMs in two zones keep running if one zone fails.

  1. Search for Virtual machines and select Create → Azure virtual machine.
  2. On Basics:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Region your region
    Availability options Availability zone
    Zone options Self-selected zone
    Availability zone select Zone 1 and Zone 2
    Virtual machine names lab-vm1 and lab-vm2 (edit the names after selecting both zones)
    Security type Standard
    Image Ubuntu Server 24.04 LTS - x64 Gen2
    Size size A of your region
    Authentication type Password
    Username azureuser
    Password the VM password
    Public inbound ports None

    One VM in each zone

    Selecting two zones creates two VMs, one in each zone.

  3. On Disks, set OS disk type to Standard SSD (locally-redundant storage). Keep Delete with VM checked.

    Don't skip this

    The default is Premium SSD, which is blocked with [LAB-P03D-VM-DISK].

  4. On Networking:

    • Public IP: None.
    • NIC network security group: None.
    • Load balancing options: None.
    • Check Delete NIC when VM is deleted.
  5. On Monitoring, set Boot diagnostics to Disable.
  6. Select Review + create, then Create. Wait for it to complete, then select Go to resource.

Task 2: Resize a VM and manage its disks

Change the size

  1. Open lab-vm1. On the Overview page, select Stop and confirm. Wait for Stopped (deallocated).
  2. Under Availability + scale, select Size.
  3. Select size B of your region and select Resize. Confirm. Only sizes from your region's list work.

Why stop first?

Changing the size of a running VM can restart it, and a size must be available on the hardware where the VM runs. Stopping (deallocating) lets Azure move it.

Add and move a data disk

  1. Under Settings, select Disks.
  2. Under Data disks, select + Create and attach a new disk and set:

    Setting Value
    Disk name vm1-disk1
    Storage type Standard HDD (locally-redundant storage)
    Size (GiB) 32
  3. Select Apply.

  4. When the disk is created, select Detach next to it, then Apply. The disk is not deleted. It is only detached.
  5. In the portal search, type Disks and select it. Open vm1-disk1.
  6. Under Settings, select Size + performance. Change the storage type to Standard SSD, then Save.
  7. Go back to lab-vm1 → Disks → Attach existing disks.
  8. Under Disk name, select vm1-disk1. Check that the type is now Standard SSD, then select Apply.

Think about it

You changed the disk type while it was detached. Why is that easier than changing it on a running VM?

Task 3: Create a virtual machine scale set

A scale set runs a group of identical VMs that share a load balancer and can grow and shrink. You use Uniform orchestration, where all instances are the same.

  1. Search for Virtual machine scale sets and select + Create.
  2. On Basics:

    Setting Value
    Resource group rg-CLOUD-LAB-GRP-N
    Name vmss1
    Region your region
    Availability zone Zones 1, 2, 3
    Orchestration mode Uniform
    Security type Standard
    Scaling mode Manual
    Initial instance count 2
    Image Ubuntu Server 24.04 LTS - x64 Gen2
    Size size A of your region
    Authentication type Password
    Username azureuser
    Password the VM password

    If a zone gives an error

    If the deployment fails with a capacity error for a zone, set Availability zone to None and try again. The lab works the same way.

    Uniform only

    Flexible is the default in the portal, and it is blocked with [LAB-P15C-VMSS-MODE]. Select Uniform.

  3. On Spot, take the defaults (no Spot).

  4. On Disks, set OS disk type to Standard SSD (locally-redundant storage).
  5. On Networking, select Edit virtual network: name vmss-vnet, address range 10.82.0.0/20 (replace the default), subnet subnet0 with range 10.82.0.0/24. Select OK.
  6. Select the Edit network interface icon and set:

    • NIC network security group: Advanced, then Create new. Name it vmss1-nsg and add an inbound rule: source Any, destination Any, service HTTP, action Allow, priority 1010, name allow-http. Select Add, then OK.
    • Public IP address: Disabled.

    No public address per instance

    Each instance would get its own public IP. You use the load balancer's address instead.

  7. Under Load balancing, select Azure load balancer and Create a load balancer. Name it vmss-lb, keep the defaults, and select Create.

  8. On Management, set Boot diagnostics to Disable. On Health and Advanced, take the defaults.
  9. Select Review + create, then Create.
  10. When it completes, open vmss1 → Instances. You should see 2 instances.

Task 4: Scale the scale set

  1. Open vmss1. Under Availability + scale, select Scaling.
  2. Select Custom autoscale, and set Scale mode to Scale based on a metric.
  3. Select + Add a rule to add the scale-out rule:

    Setting Value
    Metric source Current resource (vmss1)
    Metric name Percentage CPU
    Operator Greater than
    Metric threshold 70
    Duration 10 minutes
    Time grain statistic Average
    Operation Increase percent by
    Percentage 50
    Cool down 5 minutes

    Select Add.

  4. Add the scale-in rule: operator Less than, threshold 30, operation Decrease percent by, percentage 50. Select Add.

  5. Under Instance limits, set Minimum 2, Maximum 4, Default 2.

    Maximum 4

    The highest allowed maximum is 4.

  6. Select Save.

  7. Open Instances and check that there are 2 instances.

See the limit

  1. Go back to Scaling and change Maximum to 10. Select Save.
  2. The save is blocked with a message that starts with [LAB-P16-AUTOSCALE]. Read it.
  3. Set Maximum back to 4 and select Save.

Think about it

In this lab nothing generates load, so the scale set stays at 2 instances. What would have to happen for it to scale out? What does the cool down do?

Task 5: Clean up

Delete in this order:

  1. Delete the autoscale setting: on vmss1 → Scaling, select Manual scale and Save, or delete the setting from Monitor → Autoscale.
  2. Delete vmss1.
  3. Delete the load balancer vmss-lb and its public IP address.
  4. Delete vmss-vnet and vmss1-nsg.
  5. Delete the VMs lab-vm1 and lab-vm2.
  6. Delete the data disk vm1-disk1 (it stays after the VM is deleted).
  7. Delete the virtual network and any other resources the VM wizard created.
  8. Check that your resource group has none of these resources, including disks, network interfaces and public IP addresses.

Check your work

  • lab-vm1 and lab-vm2 ran in different availability zones.
  • lab-vm1 was resized to size B, and vm1-disk1 ended up as a Standard SSD attached to it.
  • vmss1 had 2 instances.
  • Autoscale was set to minimum 2 and maximum 4, and a maximum of 10 was blocked.
  • Your resource group is empty again.

Key points

  • Availability zones protect against the failure of one data center. Put each VM of a service in a different zone.
  • You resize a VM by stopping it, picking a new size, and starting it again. Data disks are separate resources.
  • A scale set runs identical instances behind a load balancer.
  • Autoscale adds or removes instances from rules, between a minimum and a maximum.
  • Delete VMs, disks, public IPs and scale sets when you finish, or they keep costing money.