Skip to main content

Command Palette

Search for a command to run...

Lab 08: Manage Azure Virtual Machines

Updated
5 min read

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

  1. Sign In: Log in to the Azure portal (https://portal.azure.com).

  2. 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-vm1 and az104-vm2.

      • Availability options: Availability zone

      • Availability zone: Check both Zone 1 and Zone 2. This creates two VMs, one in each zone.

      • Azure Spot instance: Unchecked

      • Size: Standard_D2s_v3

      • Password: (Provide a strong password)

      • Public inbound ports: None

    • Disks:

      • OS disk type: Premium SSD

      • Delete with VM: Checked (default)

      • Enable Ultra Disk compatibility: Unchecked

    • Networking: Accept the defaults, but set Load Balancing Options to None and Delete public IP and NIC when VM is deleted to Checked.

    • Management: Patch orchestration options: Azure orchestrated

    • Monitoring:Boot diagnostics: Disable

    • Advanced: Accept the defaults.

    • Review + create: Verify and click "Create."

Task 2: Manage VM Scaling

  1. Resize VM (Vertical Scaling):

    • Go to the az104-vm1 VM resource.

    • Under "Settings," select "Size."

    • Choose Standard_DS1_v2

    • Click "Resize." Confirm the change if prompted.

  2. Manage Data Disk:

    • Under "Settings," select "Disks."

    • Click "+ Create and attach a new disk."

      • Disk name: vm1-disk1

      • Storage type: Standard HDD

      • Size (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.

  3. 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."

  4. Reattach Disk:

    • Go back to the az104-vm1 VM.

    • 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

  1. Create VMSS: Search for and select "Virtual machine scale sets." and click "+ Create."

    • Basics:

      • Virtual machine scale set name: vmss1

      • Region: (US) East US

      • Availability zone: Select Zone 1, Zone 2, and Zone 3.

      • Orchestration mode: Uniform

      • Scaling 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-vnet

        • Address range: 10.82.0.0/20 (delete the existing default range)

        • Subnet name: subnet0

        • Subnet range: 10.82.0.0/24

        • Click "OK."

    • Click the "Edit network interface" icon (pencil) to the right of the NIC entry.

      • NIC network security group: Advanced

      • Configure network security group: Click "Create new."

        • Name: vmss1-nsg

        • Click "Add an inbound rule."

          • Source: Any

          • Source port ranges: *

          • Destination: Any

          • Service: HTTP

          • Action: Allow

          • Priority: 1010

          • Name: allow-http

        • Click "Add."

        • Click "OK."

  • Public IP address: Enabled

  • Click "OK."

  • Load Balancing:

    • Load balancing options: Azure load balancer

    • Select a load balancer: Click Create new

      • Enter the Load Balancer Name: vmss-lb

      • Take 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."

  1. Wait for Deployment: This will take about 5 minutes.

Task 4: Scale VMSS (Autoscaling)

  1. Configure Autoscaling:

    • Go to the vmss1 resource.

    • Under Settings, choose Availability + Scale, and then Scaling.

    • 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 Host

      • Metric name: Percentage CPU

      • Operator: Greater than

      • Metric threshold to trigger scale action: 70

      • Duration (minutes): 10

      • Time grain statistic: Average

      • Operation: Increase percent by

      • Cool down (minutes): 5

      • Percentage: 50

      • Select Add.

  • Scale In Rule (Decrease Instances):

    • Select Add a rule

    • Metric Source: Current Resource

    • Metric namespace: Virtual Machine Host

    • Metric name: Percentage CPU

    • Operator: Less than

    • Threshold: 30

    • Operation: Decrease percent by

    • Percentage: 50

    • Select Add.

    • Instance Limits:

      • Minimum: 2

      • Maximum: 10

      • Default: 2

  • Click "Save."

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

Task 5: Create VM with PowerShell (Optional)

  1. Launch Cloud Shell (PowerShell): Click the Cloud Shell icon in the portal (or go to https://shell.azure.com). Choose PowerShell.

  2. 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.

  3. 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)

  1. Launch Cloud Shell (Bash): Click the Cloud Shell icon, and choose Bash.

  2. Create VM:

    Bash

     az vm create --name myCLIVM --resource-group az104-rg8 --image Ubuntu2204 --admin-username localadmin --generate-ssh-keys
    
  3. Verify 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.

2 views

More from this blog

A

An Azure Cloud Lab Journey...

45 posts