Lab 08: Manage Azure Virtual Machines
For complete lab instructions, see the full guide on GitHub.
Objective: This lab explores Azure Virtual Machines (VMs) and Virtual Machine Scale Sets (VMSS). You'll create and manage individual VMs, resize them, and then create a VMSS with autoscaling.
Key Concepts:
Availability Zones: Physically separate locations within an Azure region, providing high availability and fault tolerance. Deploying VMs across zones protects against single-point-of-failure within a region.
VM Size (SKU): Determines the compute resources (CPU, memory) allocated to a VM. Resizing a VM changes its SKU.
Managed Disks: Azure-managed storage for VMs. You can change the disk type (Standard HDD, Standard SSD, Premium SSD) and size.
Virtual Machine Scale Set (VMSS): A group of identical, load-balanced VMs that can automatically scale in or out based on demand or a schedule.
Autoscaling: Automatically adjusting the number of VM instances in a VMSS based on metrics like CPU utilization.
Orchestration Modes: Uniform (identical instances, suitable for stateless applications, the focus of this lab) and Flexible (allows more heterogeneity, suitable for a wider range of workloads, including stateful applications).
Job skills
Task 1: Deploy zone-resilient Azure virtual machines by using the Azure portal.
Task 2: Manage compute and storage scaling for virtual machines.
Task 3: Create and configure Azure Virtual Machine Scale Sets.
Task 4: Scale Azure Virtual Machine Scale Sets.
Task 5: Create a virtual machine using Azure PowerShell (optional 1).
Task 6: Create a virtual machine using the CLI (optional 2).
Task 1: Deploy Zone-Resilient VMs
Sign In: Log in to the Azure portal (https://portal.azure.com).
Create VMs: Search for and select "Virtual machines" and click "+ Create" -> "Azure virtual machine."
Basics:
Virtual machine names: After selecting both Availability Zones (next step), select Edit Names and use
az104-vm1andaz104-vm2.Availability options:
Availability zoneAvailability zone: Check both
Zone 1andZone 2. This creates two VMs, one in each zone.Azure Spot instance:
UncheckedSize:
Standard_D2s_v3Password: (Provide a strong password)
Public inbound ports:
None
Disks:
OS disk type:
Premium SSDDelete with VM:
Checked(default)Enable Ultra Disk compatibility:
Unchecked
Networking: Accept the defaults, but set Load Balancing Options to
Noneand Delete public IP and NIC when VM is deleted toChecked.Management: Patch orchestration options:
Azure orchestratedMonitoring:Boot diagnostics:
DisableAdvanced: Accept the defaults.
Review + create: Verify and click "Create."
Task 2: Manage VM Scaling
Resize VM (Vertical Scaling):
Go to the
az104-vm1VM resource.Under "Settings," select "Size."
Choose
Standard_DS1_v2Click "Resize." Confirm the change if prompted.
Manage Data Disk:
Under "Settings," select "Disks."
Click "+ Create and attach a new disk."
Disk name:
vm1-disk1Storage type:
Standard HDDSize (GiB):
32
Click "Save."
After creation, click the "Detach" icon (far right) for
vm1-disk1.Click Apply. This detaches the disk but keeps it in storage.
Change Disk Type:
Search for and select "Disks."
Select
vm1-disk1.Under "Settings," select "Size + performance."
Change the "Storage type" to
Standard SSD.Click "Save."
Reattach Disk:
Go back to the
az104-vm1VM.Select "Disks."
Under "Data disks," click "Attach existing disks."
Disk name: Select
vm1-disk1.Verify the disk type is now
Standard SSD.Click Apply.
Task 3: Create Virtual Machine Scale Set
Create VMSS: Search for and select "Virtual machine scale sets." and click "+ Create."
Basics:
Virtual machine scale set name:
vmss1Region:
(US) East USAvailability zone: Select
Zone 1,Zone 2, andZone 3.Orchestration mode:
UniformScaling Options: Review and take the defaults. We will change this in the next task.
Size:
Standard_D2s_v3
Disks: Accept the defaults.

Networking: Click "Create virtual network" (below the Virtual network textbox).
Name:
vmss-vnetAddress range:
10.82.0.0/20(delete the existing default range)Subnet name:
subnet0Subnet range:
10.82.0.0/24Click "OK."
Click the "Edit network interface" icon (pencil) to the right of the NIC entry.
NIC network security group:
AdvancedConfigure network security group: Click "Create new."
Name:
vmss1-nsgClick "Add an inbound rule."
Source:
AnySource port ranges:
*Destination:
AnyService:
HTTPAction:
AllowPriority:
1010Name:
allow-http
Click "Add."
Click "OK."

Public IP address:
EnabledClick "OK."

Load Balancing:
Load balancing options:
Azure load balancerSelect a load balancer: Click Create new
Enter the Load Balancer Name:
vmss-lbTake the defaults, and select Create.

Management: Disable Boot Diagnostics.
Health: Review the defaults (no changes).
Advanced: Review the defaults (no changes).
Review + create: Verify and click "Create."
- Wait for Deployment: This will take about 5 minutes.
Task 4: Scale VMSS (Autoscaling)
Configure Autoscaling:
Go to the
vmss1resource.Under Settings, choose
Availability + Scale, and thenScaling.Select
Custom autoscale.Scale mode:
Scale based on a metric
Click "+ Add a rule."
Scale Out Rule (Increase Instances):
Metric source:
Current resource (vmss1)Metric namespace:
Virtual Machine HostMetric name:
Percentage CPUOperator:
Greater thanMetric threshold to trigger scale action:
70Duration (minutes):
10Time grain statistic:
AverageOperation:
Increase percent byCool down (minutes):
5Percentage:
50Select Add.

Scale In Rule (Decrease Instances):
Select Add a rule
Metric Source:
Current ResourceMetric namespace:
Virtual Machine HostMetric name:
Percentage CPUOperator:
Less thanThreshold:
30Operation:
Decrease percent byPercentage:
50Select Add.
Instance Limits:
Minimum:
2Maximum:
10Default:
2
Click "Save."


- Monitor Instances:
- On the
vmss1page, select "Instances." This is where you'd monitor the number of running VM instances as the scale set scales in and out.
- On the

Task 5: Create VM with PowerShell (Optional)
Launch Cloud Shell (PowerShell): Click the Cloud Shell icon in the portal (or go to https://shell.azure.com). Choose PowerShell.
Create VM:
PowerShell
New-AzVm ` -ResourceGroupName 'az104-rg8' ` -Name 'myPSVM' ` -Location 'East US' ` -Image 'Win2019Datacenter' ` -Zone '1' ` -Size 'Standard_D2s_v3' ` -Credential (Get-Credential)Enter a username and password when prompted.
Verify and Deallocate:
PowerShell
Get-AzVM -ResourceGroupName 'az104-rg8' -Status Stop-AzVM -ResourceGroupName 'az104-rg8' -Name 'myPSVM' -Force Get-AzVM -ResourceGroupName 'az104-rg8' -Status
Task 6: Create VM with Azure CLI (Optional)
Launch Cloud Shell (Bash): Click the Cloud Shell icon, and choose Bash.
Create VM:
Bash
az vm create --name myCLIVM --resource-group az104-rg8 --image Ubuntu2204 --admin-username localadmin --generate-ssh-keysVerify and Deallocate:
Bash
az vm show --name myCLIVM --resource-group az104-rg8 --show-details az vm deallocate --resource-group az104-rg8 --name myCLIVM az vm show --name myCLIVM --resource-group az104-rg8 --show-details
For complete lab instructions, see the full guide on GitHub.