Skip to content
Back to Cloud Services

Azure Virtual Machines

IaaS compute offering Linux and Windows VMs with hundreds of sizes, ephemeral OS disks, spot pricing, and proximity placement groups for low-latency clusters.

AzureIntermediate

Why

VMs give full OS control for software that cannot run in PaaS — legacy apps, custom kernels, GPU ML workloads, and clustered databases. Azure offers Spot VMs at up to 90% discount for interruptible workloads and ephemeral OS disks for fast reimage. Azure holds 21% cloud market share (Synergy Research Q4 2024).

Azure is the default for enterprises with Microsoft 365 / Active Directory estates — 95% of Fortune 500 use Azure. AKS and Cosmos DB are first-class for .NET workloads.

When

Use VMs when you need full OS access, custom software not supported by PaaS, GPU instances, or lift-and-shift migrations. Prefer App Service/Functions for web apps, AKS for containers, and Spot VMs for batch/CI jobs that tolerate eviction.

How

1. Create a resource group and VNet with a subnet. 2. Create a VM with az vm create, picking an image (UbuntuLTS, Win2019Datacenter) and size. 3. Open ports via NSG rules (only open what you need — never 22 to 0.0.0.0/0 in prod). 4. Attach a data disk for persistent storage. 5. Enable boot diagnostics and Azure Monitor for the VM. 6. Use cloud-init or a custom script extension to provision on first boot. ```bash az vm create --name myvm --resource-group rg --image Ubuntu2204 --size Standard_D2s_v5 --vnet-name myvnet --subnet default --admin-username azureuser --ssh-key-values ~/.ssh/id_rsa.pub --public-ip-sku Standard az vm open-port --name myvm --resource-group rg --port 80 ```

Example

cloud-init to install Docker and run nginx on first boot: ```yaml #cloud-config package_update: true packages: [docker.io] runcmd: - systemctl enable --now docker - docker run -d --name web --restart unless-stopped -p 80:80 nginx:stable ``` Create the VM with this cloud-init: ```bash az vm create --name myvm --resource-group rg --image Ubuntu2204 --size Standard_B2s --custom-data ./cloud-init.yaml --admin-username azureuser --ssh-key-values ~/.ssh/id_rsa.pub ```

Common Problems

  • ⚠SSH connection refused/timeout — NSG is blocking port 22 or the public IP is Standard and not allocated; verify the NSG inbound rule and that the VM is running.
  • ⚠VM is slow despite large size — you may be IOPS-limited on the OS disk; use Premium SSD or Ultra Disk for high IOPS, and put data on a separate data disk.
  • ⚠Spot VM evicted mid-job — Spot is best-effort; checkpoint long jobs, or use Spot with a defined eviction policy and re-deploy on eviction signal.

Best Practices

  • ✓Never expose SSH (22) or RDP (3389) to 0.0.0.0/0 in production — use Azure Bastion for secure RDP/SSH over TLS without a public IP on the VM.
  • ✓Use Managed Disks (default) not unmanaged VHDs — they handle replication, snapshots, and encryption automatically.
  • ✓Tag VMs with owner, cost-center, and environment; use Azure Cost Management alerts to catch runaway spend on oversized VMs.

FAQ

What is Azure Virtual Machines and what problem does it solve?

IaaS compute offering Linux and Windows VMs with hundreds of sizes, ephemeral OS disks, spot pricing, and proximity placement groups for low-latency clusters. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with Azure Virtual Machines in 5 minutes?

Two steps to run it: (1) Create a resource group and VNet with a subnet.; (2) Create a VM with az vm create, picking an image (UbuntuLTS, Win2019Datacenter) and size.. Validate on the free tier first, then wire into production.

What is the #1 pitfall with Azure Virtual Machines?

The most frequent issue is: SSH connection refused/timeout — NSG is blocking port 22 or the public IP is Standard and not allocated; verify the NSG inbound rule and that the VM is running.. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for Azure Virtual Machines?

Best practices for Azure Virtual Machines include: Never expose SSH (22) or RDP (3389) to 0.0.0.0/0 in production — use Azure Bastion for secure RDP/SSH over TLS without a public IP on the VM.; Use Managed Disks (default) not unmanaged VHDs — they handle replication, snapshots, and encryption automatically.; Tag VMs with owner, cost-center, and environment; use Azure Cost Management alerts to catch runaway spend on oversized VMs.. The first one — "Never expose SSH (22) or RDP (3389) to 0.0.0.0/0 in production — use Azure Bastion for secure RDP/SSH over TLS without a public IP on the VM." — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with Azure Virtual Machines?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most Azure Virtual Machines options offer a free tier — validate within free quota before scaling.