Skip to content
Visual explainer 3h to learn 5 steps

Operate Azure VMs and scale sets

Run a VM or scale set with the right image, disks, network and secure admin access, and scale it on health.

By Invicly Tech, , in Microsoft Azure Cloud Engineering. About 14 minutes to read.

Topic 11 of 33

In short

An Azure virtual machine (VM) is a server you rent by the second: you pick an image, a size, disks and a network, and you look after everything inside the operating system. A Virtual Machine Scale Set runs many identical VMs from one definition, replaces unhealthy ones and adds or removes instances by rule. Admin access should go through Azure Bastion or another private path, not an SSH port open to the internet.

Think of it like this: A single VM is a rented van you drive and service yourself; a scale set is a fleet contract that swaps a broken van and adds more on busy days.

Explained simply

A virtual machine, or VM, is a computer that lives in an Azure data centre. You choose how big it is, which operating system it starts from and how much disk it gets. Azure runs the physical hardware. Everything inside the VM, from security updates to the app itself, is your job. That freedom is why VMs suit old apps, special software and anything that needs full control of the server.

Four choices shape every VM. The image is the starting operating system, such as Ubuntu 24.04 LTS or Windows Server. The size sets how many virtual CPUs and how much memory you get. Disks hold the operating system and your data. The network interface puts the VM in a subnet with a private IP address, and network security group rules decide which traffic may reach it.

You still need a way in to fix things. The old habit is a public IP with SSH on port 22 open to the world, and automated attacks start almost immediately. Azure Bastion lets you open an SSH or RDP session from the Azure Portal while the VM keeps only a private address. The Developer SKU of Bastion is free for labs in supported regions.

One VM is a single point of failure. A Virtual Machine Scale Set runs several identical VMs from one template. It can check each one's health, replace a broken instance, and add or remove instances when a metric such as CPU goes up or down. Put a load balancer in front and users see one service, not many servers.

Cost note: VMs, disks and public IPs are paid resources. A new Azure free account includes limited hours of some small B-series sizes for 12 months; check the free services page before you start. Deallocate VMs you are not using and delete the lab resource group at the end.

Press Play on a diagram to walk through it one step at a time.

LayersWhat one Azure VM is made of
  1. 1
    Your app and OS patches

    Your job: packages, updates, hardening.

  2. 2
    Image

    Marketplace or custom image, such as Ubuntu 24.04 LTS.

  3. 3
    Size

    vCPU and memory family, such as B (burstable) or D (general purpose).

  4. 4
    Disks

    OS disk plus optional data disks, all managed disks.

  5. 5
    Network interface

    Private IP in a subnet, NSG rules, optional public IP.

FlowHow a scale set reacts to load and failure
  1. 1
    Health probe

    Application Health extension checks /healthz on each instance.

  2. 2
    Unhealthy instance

    Automatic repairs delete and recreate it.

  3. 3
    Metric rises

    Average CPU above 70 percent for 5 minutes.

  4. 4
    Autoscale rule fires

    Add instances up to the maximum count.

  5. 5
    Load drops

    Scale-in rule removes instances down to the minimum.

CycleVM power states and billing
  1. 1
    Running

    Compute, disks and IPs are billed.

  2. 2
    Stopped from inside the OS

    Still allocated, compute still billed.

  3. 3
    Deallocated

    Compute stops billing; disks still billed.

  4. 4
    Started again

    May land on a new host; temporary disk is empty.

  5. Back to step 1
LayersA scale set behind a load balancer
  1. 1
    Users

    Call one public or private address.

  2. 2
    Load balancer

    Health probe decides which instances get traffic.

  3. 3
    Scale set instances

    Identical VMs spread across zones.

  4. 4
    Autoscale and repairs

    Change the count and replace unhealthy instances.

  5. 5
    Image and model

    One definition every instance is built from.

In depth

Choosing an image and a size

Start from a supported image: a Marketplace image such as Canonical Ubuntu 24.04 LTS, or your own image stored in an Azure Compute Gallery so every server starts the same way. Then pick a size. Size names follow a pattern: the letter is the family, the number is the vCPU count, and extra letters add features. Standard_D4s_v5 is a general purpose D-series size with 4 vCPUs, the s means it supports Premium SSD, and v5 is the generation.

Measure before you choose. Run the app on a small size, watch CPU, memory and disk metrics under realistic load, then resize. Resizing usually restarts the VM, and not every size is available in every region or zone, so check with az vm list-sizes or az vm list-skus first. B-series burstable sizes are cheap for light, spiky work but run out of CPU credits under steady load.

  • B: burstable, cheap, for light or spiky load
  • D: general purpose, balanced CPU and memory
  • E: memory optimised, for caches and databases
  • F: compute optimised, for CPU-heavy work
  • N: GPU sizes, for graphics and AI

Disks: OS, data and temporary

Every VM has a managed OS disk. You can attach managed data disks for application data, and most sizes also come with a temporary disk on the host. The temporary disk is fast but its contents can be lost on a redeploy, resize or host maintenance, so use it only for scratch files and swap.

Managed disks come in several types: Standard HDD for backups and rarely used data, Standard SSD for light production and dev, Premium SSD for production workloads, and Premium SSD v2 and Ultra Disk when you need to set IOPS and throughput separately from size. Keep data on a data disk, not the OS disk. Then you can rebuild or replace the OS and reattach the data. Snapshots and Azure Backup protect disks; a disk on its own is not a backup.

  • OS disk: boots the VM, keep it small
  • Data disk: your app data, survives OS rebuilds
  • Temporary disk: scratch only, may be wiped
  • Format and mount new data disks inside the OS yourself

Admin access without a public port

Azure Bastion is a managed jump host. You connect to Bastion over HTTPS from the Portal, and Bastion opens SSH or RDP to the VM's private IP inside the virtual network. The VM needs no public IP and no inbound rule from the internet.

There are four SKUs. Developer is free, uses shared infrastructure, connects to one VM at a time in the same VNet, and is available in selected regions, which makes it ideal for this lab. Basic, Standard and Premium are paid, dedicated hosts that need a subnet named AzureBastionSubnet of at least /26. Standard and Premium add native client support, so you can run az network bastion ssh from your own terminal. Other options are a VPN into the VNet, or just-in-time VM access in Microsoft Defender for Cloud, which opens the port briefly for one source IP.

SequenceAn SSH session through Azure Bastion
Admin browser
Azure Portal
Azure Bastion
Private VM
  1. 1Sign in with Entra ID, choose Connect
    Admin browser to Azure Portal: Sign in with Entra ID, choose Connect
  2. 2Open session over HTTPS 443
    Azure Portal to Azure Bastion: Open session over HTTPS 443
  3. 3SSH to private IP on port 22
    Azure Bastion to Private VM: SSH to private IP on port 22
  4. 4Shell output
    Private VM to Azure Bastion: Shell output
  5. 5Terminal streamed in the browser
    Azure Bastion to Admin browser: Terminal streamed in the browser

Health checks and scaling in a scale set

A scale set in Flexible orchestration mode, the default for new scale sets, creates normal VMs from one model. Two features make it self-managing. First, the Application Health extension runs inside each instance and calls an endpoint you choose, such as http://localhost/healthz, then reports healthy or unhealthy. With automatic instance repairs turned on, the scale set deletes and recreates an instance that stays unhealthy past a grace period.

Second, autoscale settings in Azure Monitor change the instance count. You set a minimum, a maximum and a default, plus rules such as add one instance when average CPU is above 70 percent for 5 minutes and remove one when it is below 30 percent for 10 minutes. Always pair a scale-out rule with a scale-in rule, keep a cool-down so the count does not flap, and set the minimum to at least two so one failure does not take the service down.

  • Minimum 2 instances for availability
  • Scale out fast, scale in slowly
  • Spread instances across availability zones where offered
  • Health endpoint should test the app, not just the OS

Learn it in 5 short steps

About 35m each. Track them with a timer in your plan.

  1. 1
    Choose image and size~35m
  2. 2
    Attach disks~35m
  3. 3
    Use Bastion instead of public SSH~35m
  4. 4
    Add health checks~35m
  5. 5
    Scale with a scale set~35m

Key points

  • With a VM you own the operating system: patching, agents, firewall and backups inside it are your job.
  • Choose the size from measured CPU, memory and disk needs; you can resize later, usually with a restart.
  • Keep data on a separate data disk so you can rebuild the OS disk without losing it.
  • Use Azure Bastion or a private network path for SSH and RDP instead of a public port 22 or 3389.
  • A scale set with health checks and autoscale turns pets you repair by hand into cattle you replace.

Key terms

Tap a card to flip it. 0/6 known

Examples

bash
# Private VM with no public IP and a 32 GB data disk
az vm create -g rg-lab-compute -n vm-api-01 \
  --image Ubuntu2404 --size Standard_B2s \
  --vnet-name vnet-lab --subnet snet-app \
  --public-ip-address "" --admin-username azureuser \
  --generate-ssh-keys --data-disk-sizes-gb 32

# Check its private IP and power state
az vm show -d -g rg-lab-compute -n vm-api-01 \
  --query "{ip:privateIps, state:powerState}" -o table

Creates a VM that can only be reached privately, for example through Bastion.

A private web VM you reach through Bastion

Prerequisites: a lab resource group with a budget alert, and a VNet with a subnet for the app. Step 1: create the VM with no public IP. Step 2: in the Portal, open the VM, choose Connect, then Bastion, and deploy the Developer SKU if offered in your region. Step 3: sign in with the SSH key the CLI generated and install nginx. Step 4: check evidence: the VM overview shows no public IP, and curl from inside the VM returns the nginx page. Step 5: clean up by deleting the resource group.

bash
az group create -n rg-lab-compute -l westeurope --tags env=lab owner=you
az network vnet create -g rg-lab-compute -n vnet-lab \
  --address-prefixes 10.0.0.0/16 --subnet-name snet-app --subnet-prefixes 10.0.1.0/24
az vm create -g rg-lab-compute -n vm-web-01 --image Ubuntu2404 \
  --size Standard_B1s --vnet-name vnet-lab --subnet snet-app \
  --public-ip-address "" --admin-username azureuser --generate-ssh-keys
# after connecting through Bastion, inside the VM:
sudo apt-get update && sudo apt-get install -y nginx
curl -s localhost | head -n 4
# cleanup
az group delete -n rg-lab-compute --yes --no-wait

A self-healing scale set

Goal: two web instances that replace themselves when the app fails and grow under load. Step 1: create a Flexible scale set with two instances. Step 2: add the Application Health extension pointed at the app's health path. Step 3: turn on automatic repairs with a 30 minute grace period. Step 4: add autoscale between 2 and 5 instances on CPU. Evidence: az vmss get-instance-view shows health per instance, and stopping nginx on one instance leads to a replacement after the grace period.

bash
az vmss create -g rg-lab-compute -n vmss-web --image Ubuntu2404 \
  --orchestration-mode Flexible --instance-count 2 --vm-sku Standard_B1s \
  --vnet-name vnet-lab --subnet snet-app --admin-username azureuser --generate-ssh-keys
az vmss extension set -g rg-lab-compute --vmss-name vmss-web \
  --name ApplicationHealthLinux --publisher Microsoft.ManagedServices --version 2.0 \
  --settings '{"protocol":"http","port":80,"requestPath":"/healthz"}'
az vmss update -g rg-lab-compute -n vmss-web \
  --enable-automatic-repairs true --automatic-repairs-grace-period 30
az monitor autoscale create -g rg-lab-compute -n as-web --resource vmss-web \
  --resource-type Microsoft.Compute/virtualMachineScaleSets --min-count 2 --max-count 5 --count 2
az monitor autoscale rule create -g rg-lab-compute --autoscale-name as-web \
  --condition "Percentage CPU > 70 avg 5m" --scale out 1
az monitor autoscale rule create -g rg-lab-compute --autoscale-name as-web \
  --condition "Percentage CPU < 30 avg 10m" --scale in 1

Quick reference

  • az vm list-sizes -l westeurope -o table lists sizes in a region
  • az vm deallocate stops compute billing; shutting down inside the OS does not
  • --public-ip-address "" on az vm create means no public IP
  • Bastion Developer SKU: free, one VM at a time, same VNet, selected regions
  • Dedicated Bastion SKUs need a subnet named AzureBastionSubnet, /26 or larger
  • Temporary disk contents can vanish; keep data on a managed data disk
  • Scale sets: minimum 2 instances, scale-out and scale-in rules, health extension on

Common mistakes

  • Leaving port 22 or 3389 open to the internet. Bots find it within minutes; use Bastion or just-in-time access.
  • Stopping a VM from inside the OS. It stays allocated and billed; deallocate it with az vm deallocate or the Portal.
  • Autoscaling on CPU alone when the app is slow because of a database. More instances will not help.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1You shut down a VM with sudo shutdown now. What happens to compute billing?

Question 2

2Where should an app keep data that must survive rebuilding the operating system?

Question 3

3Which Bastion SKU is free and suitable for a single-VM lab?

Question 4

4A scale set keeps an instance whose web app has crashed. What is most likely missing?

Question 5

5What does the s in Standard_D4s_v5 indicate?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    List the B-series sizes available in your lab region and note the vCPU and memory of Standard_B2s.

  2. Exercise 2medium

    Attach a new 32 GB data disk to vm-web-01, then format and mount it at /data so it survives a reboot.

  3. Exercise 3hard

    Prove that your scale set heals itself. Break the app on one instance and show the evidence that it was replaced.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Do I pay for a stopped Azure VM?
If it is only shut down from inside, yes, compute is still billed. When it is deallocated, compute stops, but you still pay for its disks and any static public IP.
Is Azure Bastion free?
The Developer SKU is free and fine for labs in supported regions. Basic, Standard and Premium are billed by the hour plus outbound data.
Should I use a scale set or App Service?
Use App Service or Container Apps when your app fits their supported runtimes; they patch the OS for you. Use VMs and scale sets when you need full OS control or software that needs a real server.
Can I change a VM's size later?
Yes. Resizing usually restarts the VM, and the new size must be available in that region and zone.

Go deeper

ShareXLinkedInWhatsApp