Virtual machines

Microsoft Azure · Essentials · 12 min

VMs are the IaaS building block for anything that doesn't fit a managed platform.

An Azure virtual machine is IaaS: you choose the image, size and disks, and you own the operating system, patches and everything above it.

  • Image: a marketplace image such as Ubuntu 24.04 (Ubuntu2404 alias) or Windows Server, or your own from an Azure Compute Gallery.
  • Size: the family describes the shape: B (burstable, cheap dev boxes), D (general purpose), E (memory optimized), F (compute optimized), N (GPU). Standard_D4s_v5 means 4 vCPUs, s for premium-storage capable.
  • Disks: managed disks; the OS disk plus optional data disks in Standard HDD, Standard SSD, Premium SSD, Premium SSD v2 or Ultra tiers. Size and tier set IOPS and throughput.
  • Networking: a NIC in a VNet subnet, an NSG, and optionally a public IP. For admin access prefer Azure Bastion or Entra ID login over exposing SSH to the internet.

Billing is per second of compute while the VM is allocated, plus disks always. The trap: shutting down from inside the OS or az vm stop leaves the VM allocated and billed; az vm deallocate releases the hardware and stops compute charges (disks are still billed).

Use Spot VMs for interruptible batch work at deep discounts, and cloud-init (--custom-data) to configure a VM on first boot.

Example

az vm create -g rg-demo -n vm-web01 \
  --image Ubuntu2404 --size Standard_B2s \
  --admin-username azureuser --generate-ssh-keys \
  --public-ip-sku Standard --custom-data cloud-init.yaml

az vm open-port -g rg-demo -n vm-web01 --port 80
az vm list -d -o table --query "[].{name:name, state:powerState, ip:publicIps}"
# vm-web01  VM running  20.13.x.x

az vm stop -g rg-demo -n vm-web01        # still allocated: compute still billed
az vm deallocate -g rg-demo -n vm-web01  # compute billing stops; disks still billed

Remember

  • You manage the OS and everything above it
  • Size family letters describe the shape (B, D, E, F, N)
  • Only deallocate stops compute charges
  • Use Bastion or Entra login rather than open SSH

Watch out for

  • Stopping a VM from inside the guest OS and assuming billing has stopped.

Check yourself

  1. Which action stops compute billing for a VM?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: learn.microsoft.com/en-us/azure/virtual-machines/overview