ComputeLesson 1 of 16

Virtual Machines

Azure Virtual Machines (VMs) give you full control over operating systems, custom software, and infrastructure — the classic IaaS building block.

Simple Explanation

A Virtual Machine is a computer running inside Microsoft's data center. You choose the OS, size, and software. Azure manages the physical hardware for you.

When to Use VMs

When NOT to Use VMs

If your workload is a web app, API, or event-driven function — App Services or Azure Functions are faster to deploy, cheaper to operate, and automatically patched. Consider VMs only when PaaS is not an option.

VM Sizes

Azure VM sizes are grouped by purpose. Always right-size from the start — you can resize later but it causes a brief restart.

SeriesPurposeCommon SKU Examples
B-seriesBurstable, low steady-state. Dev/test, light workloads.Standard_B2s, B4ms
D-seriesGeneral-purpose balanced CPU/memory. Most web apps, app servers.Standard_D2s_v3, D4s_v3
E-seriesMemory-optimized. In-memory databases, caches.Standard_E4s_v3, E8s_v3
F-seriesCompute-optimized. High-CPU workloads, game servers.Standard_F2s_v2
N-seriesGPU-equipped. ML training, rendering.Standard_NC6s_v3

Disk Types

Disk TypeBest ForMax IOPS
Standard HDDDev/test, infrequent access, archivingUp to 500
Standard SSDWeb servers, lightly loaded DBsUp to 6,000
Premium SSDProduction workloads, databases, I/O-intensiveUp to 20,000
Ultra DiskSAP HANA, top-tier SQL, real-time analyticsUp to 160,000

Visual Representation

VM Anatomy
VM
OS Disk (managed)
Data Disks (optional)
NIC + Private IP
Azure Fabric
Node (physical host)
Hypervisor
SLA: 99.9%-99.99%
You Manage
OS patches
Runtime/software
Application
Azure Manages
Hardware
Hypervisor
Physical networking

Commands

Azure CLI
# Create a resource group
az group create --name rg-web-dev --location eastus

# Create a VM (Ubuntu, Standard_B2s)
az vm create \
  --resource-group rg-web-dev \
  --name vm-web-01 \
  --image Ubuntu2204 \
  --size Standard_B2s \
  --admin-username azureuser \
  --generate-ssh-keys

# Open port 80
az vm open-port --resource-group rg-web-dev --name vm-web-01 --port 80

# List VMs
az vm list --output table

# Get public IP
az vm show --resource-group rg-web-dev --name vm-web-01 \
  --query publicIps --output tsv

# Start / Stop / Deallocate
az vm start  --resource-group rg-web-dev --name vm-web-01
az vm stop   --resource-group rg-web-dev --name vm-web-01
az vm deallocate --resource-group rg-web-dev --name vm-web-01

# Resize
az vm resize --resource-group rg-web-dev --name vm-web-01 --size Standard_D2s_v3

Hands-on

  1. Create a resource group in your nearest region.
  2. Deploy a Standard_B2s Ubuntu VM using CLI or Portal.
  3. Connect via SSH (ssh azureuser@<public-ip>).
  4. Install nginx: sudo apt install -y nginx and verify via browser.
  5. Deallocate the VM to stop billing; note the difference from Stop.

Debugging Scenario

Issue: VM is unresponsive after OS update.

Interview Questions

Beginner

What is an Azure VM?

An IaaS service providing configurable virtual computers in Azure data centers. You manage the OS and software; Azure manages the hardware.

Difference between Stop and Deallocate?

Stop keeps the VM allocated (still billed for compute). Deallocate releases the compute resources and stops billing for the VM SKU.

What is a managed disk?

A storage disk managed by Azure where you don't manage the underlying storage account. Azure handles replication, snapshots, and SLA.

Intermediate

When choose Premium SSD over Standard SSD?

When running production databases or I/O-intensive apps that need consistent low-latency and high IOPS. Standard SSD is sufficient for web servers and lightly loaded apps.

What is the SLA difference between single-instance and availability set VMs?

Single instance with Premium SSD gets 99.9% SLA. Two VMs in an availability set get 99.95%. VMs across availability zones get 99.99%.

Scenario-based

Legacy app needs a specific Windows version and custom COM component. Where do you run it?

Azure VM with the required Windows version. IaaS is the right model for software that cannot be abstracted away from OS-level dependencies.

Your VM is unreachable via SSH after patching.

Check Boot Diagnostics → screenshot. Use Serial Console for emergency recovery. If kernel issue, attach disk to recovery VM, repair bootloader, re-attach.

Real-world Usage

Most enterprises run VMs for legacy apps, domain controllers, and SQL Server instances requiring specific features not available in PaaS. New greenfield workloads increasingly move to App Services or containers.

Summary

VMs are the most flexible Azure compute option but carry the highest operational burden. Use them when PaaS options genuinely cannot satisfy the requirement. Right-size with B-series for dev/test and D-series for production apps.