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.
Before you start¶
- You are signed in to the lab directory (Getting started).
- Your lab resource group is
rg-CLOUD-LAB-GRP-N. ReplaceNwith 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 isStandard_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_B1shas 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.
- Search for Virtual machines and select Create → Azure virtual machine.
-
On Basics:
Setting Value Resource group rg-CLOUD-LAB-GRP-NRegion your region Availability options Availability zone Zone options Self-selected zone Availability zone select Zone 1 and Zone 2 Virtual machine names lab-vm1andlab-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 azureuserPassword the VM password Public inbound ports None One VM in each zone
Selecting two zones creates two VMs, one in each zone.
-
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]. -
On Networking:
- Public IP: None.
- NIC network security group: None.
- Load balancing options: None.
- Check Delete NIC when VM is deleted.
- On Monitoring, set Boot diagnostics to Disable.
- 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¶
- Open
lab-vm1. On the Overview page, select Stop and confirm. Wait for Stopped (deallocated). - Under Availability + scale, select Size.
- 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¶
- Under Settings, select Disks.
-
Under Data disks, select + Create and attach a new disk and set:
Setting Value Disk name vm1-disk1Storage type Standard HDD (locally-redundant storage) Size (GiB) 32 -
Select Apply.
- When the disk is created, select Detach next to it, then Apply. The disk is not deleted. It is only detached.
- In the portal search, type Disks and select it. Open
vm1-disk1. - Under Settings, select Size + performance. Change the storage type to Standard SSD, then Save.
- Go back to
lab-vm1→ Disks → Attach existing disks. - 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.
- Search for Virtual machine scale sets and select + Create.
-
On Basics:
Setting Value Resource group rg-CLOUD-LAB-GRP-NName vmss1Region your region Availability zone Zones 1, 2, 3 Orchestration mode Uniform Security type Standard Scaling mode Manual Initial instance count 2Image Ubuntu Server 24.04 LTS - x64 Gen2 Size size A of your region Authentication type Password Username azureuserPassword 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. -
On Spot, take the defaults (no Spot).
- On Disks, set OS disk type to Standard SSD (locally-redundant storage).
- On Networking, select Edit virtual network: name
vmss-vnet, address range10.82.0.0/20(replace the default), subnetsubnet0with range10.82.0.0/24. Select OK. -
Select the Edit network interface icon and set:
- NIC network security group: Advanced, then Create new. Name it
vmss1-nsgand add an inbound rule: source Any, destination Any, service HTTP, action Allow, priority1010, nameallow-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.
- NIC network security group: Advanced, then Create new. Name it
-
Under Load balancing, select Azure load balancer and Create a load balancer. Name it
vmss-lb, keep the defaults, and select Create. - On Management, set Boot diagnostics to Disable. On Health and Advanced, take the defaults.
- Select Review + create, then Create.
- When it completes, open
vmss1→ Instances. You should see 2 instances.
Task 4: Scale the scale set¶
- Open
vmss1. Under Availability + scale, select Scaling. - Select Custom autoscale, and set Scale mode to Scale based on a metric.
-
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 70Duration 10minutesTime grain statistic Average Operation Increase percent by Percentage 50Cool down 5minutesSelect Add.
-
Add the scale-in rule: operator Less than, threshold
30, operation Decrease percent by, percentage50. Select Add. -
Under Instance limits, set Minimum
2, Maximum4, Default2.Maximum 4
The highest allowed maximum is 4.
-
Select Save.
- Open Instances and check that there are 2 instances.
See the limit¶
- Go back to Scaling and change Maximum to
10. Select Save. - The save is blocked with a message that starts with
[LAB-P16-AUTOSCALE]. Read it. - Set Maximum back to
4and 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:
- Delete the autoscale setting: on
vmss1→ Scaling, select Manual scale and Save, or delete the setting from Monitor → Autoscale. - Delete
vmss1. - Delete the load balancer
vmss-lband its public IP address. - Delete
vmss-vnetandvmss1-nsg. - Delete the VMs
lab-vm1andlab-vm2. - Delete the data disk
vm1-disk1(it stays after the VM is deleted). - Delete the virtual network and any other resources the VM wizard created.
- Check that your resource group has none of these resources, including disks, network interfaces and public IP addresses.
Check your work¶
-
lab-vm1andlab-vm2ran in different availability zones. -
lab-vm1was resized to size B, andvm1-disk1ended up as a Standard SSD attached to it. -
vmss1had 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.