Azure Virtual Machines: Deploy and Manage VMs in the Cloud

Azure Virtual Machines (VMs) are the foundation of IaaS on Azure. They give you full control over the operating system, installed software, and configuration — just like a physical server, but running in Microsoft's data centers. Whether you're lifting and shifting an on-premises workload or building a custom environment that managed services can't satisfy, Azure VMs are the right tool.

Choosing the Right VM Size

Azure offers hundreds of VM sizes organized into families, each optimized for a different workload type:

  • B-series (Burstable): Low-cost VMs for workloads with variable CPU usage. Ideal for dev/test, small web servers, and CI agents.
  • D-series (General Purpose): Balanced CPU and memory. The workhorse for most production workloads.
  • E-series (Memory Optimized): High memory-to-CPU ratio. Good for databases, caches, and in-memory analytics.
  • F-series (Compute Optimized): High CPU-to-memory ratio. Suited for batch processing, gaming servers, and CPU-heavy apps.
  • N-series (GPU): NVIDIA GPU-equipped VMs for machine learning training, rendering, and HPC.

Start with a B2s (2 vCPUs, 4 GB RAM) for learning and development. Move to D-series for production web and application tiers.

Creating a VM via the Azure Portal

The Portal wizard walks you through VM creation in minutes:

  1. Navigate to Virtual Machines in the Portal and click Create > Azure virtual machine.
  2. Select your Subscription and Resource Group (create one if needed).
  3. Enter a Virtual machine name, select a Region, and choose an Availability Zone if you need HA.
  4. Select an Image (Ubuntu 22.04, Windows Server 2022, RHEL, etc.) and a VM size.
  5. Set the Administrator account: SSH public key for Linux or username/password for Windows.
  6. Configure Inbound port rules: allow SSH (22) for Linux or RDP (3389) for Windows during initial setup.
  7. Review and click Create.

Creating a VM with the Azure CLI

The CLI is faster for repeatable deployments and scripting:

# Create a resource group
az group create --name rg-vm-demo --location eastus

# Create an Ubuntu 22.04 VM with SSH key authentication
az vm create 
  --resource-group rg-vm-demo 
  --name vm-webserver 
  --image Ubuntu2204 
  --size Standard_B2s 
  --admin-username azureuser 
  --generate-ssh-keys 
  --output table

# Open port 80 for HTTP traffic
az vm open-port --port 80 --resource-group rg-vm-demo --name vm-webserver

The --generate-ssh-keys flag creates a key pair and stores the private key at ~/.ssh/id_rsa on your machine.

Connecting to Your VM

For Linux VMs, use SSH with the public IP shown in the Portal or CLI output:

# Get the public IP address
az vm show -d --resource-group rg-vm-demo --name vm-webserver --query publicIps -o tsv

# Connect via SSH
ssh azureuser@<PUBLIC_IP>

For Windows VMs, download the RDP file from the Portal (Connect > RDP) and open it with your Remote Desktop client.

Managing VM Disks

Every VM has an OS disk (managed by Azure) and optionally one or more data disks. Use Azure Managed Disks — Azure handles replication and hardware failure transparently.

  • Standard HDD: Lowest cost, suitable for backups and infrequent access.
  • Standard SSD: Better IOPS and latency for dev/test and lightly loaded production VMs.
  • Premium SSD: High IOPS and low latency for production databases and I/O-intensive apps.
  • Ultra Disk: Extreme IOPS (up to 160,000) for mission-critical databases.
# Add a 128 GB Premium SSD data disk to a running VM
az vm disk attach 
  --resource-group rg-vm-demo 
  --vm-name vm-webserver 
  --name disk-data-01 
  --size-gb 128 
  --sku Premium_LRS 
  --new

Stopping vs Deallocating

There is an important billing distinction on Azure:

  • Stopped (OS shutdown): The VM is off but still allocated on a host. You continue to be charged for compute.
  • Deallocated: Azure releases the underlying hardware. Compute charges stop. You only pay for disk storage.
# Deallocate a VM to stop compute billing
az vm deallocate --resource-group rg-vm-demo --name vm-webserver

# Start it again later
az vm start --resource-group rg-vm-demo --name vm-webserver

Cost Optimization Tips

VMs can become your largest Azure cost center. Keep costs in check with these approaches:

  • Azure Reserved Instances: Commit to 1 or 3 years and save up to 72% compared to pay-as-you-go.
  • Azure Spot VMs: Use spare Azure capacity at up to 90% discount — ideal for interruptible batch workloads.
  • Auto-shutdown: Schedule dev/test VMs to shut down automatically at night from the Portal (VM > Auto-shutdown).
  • Right-size regularly: Use Azure Advisor recommendations to identify over-provisioned VMs.

With these fundamentals in hand, you can confidently deploy, connect, and manage Azure Virtual Machines for any workload — from a simple development sandbox to a multi-tier production application.