Images, Azure Compute Gallery and VM scale sets
-
Phase 0: Before you start
-
Phase 1: The foundation
-
Phase 2: Day-to-day operations
-
Phase 3: Enterprise architecture
-
Phase 4: Troubleshooting step by step
-
Phase 5: Final project and career
Azure VM scale sets run lots of identical VMs as one group. You build the server once as an image and keep it in an Azure Compute Gallery, and the scale set stamps out copies across zones, adding or removing them by itself as the load changes.
Web farms, batch workers and Kubernetes node pools all run this way. It also brings a whole new kind of ticket, like “I changed the scale set and nothing happened” or “it won’t scale past 2”.
In the lab you’ll build a web server, turn it into an image, run two copies across zones and add autoscale rules, and then you’ll get to handle both of those tickets yourself.
| Time | You need | Cost | By the end you can |
|---|---|---|---|
| About 75 minutes (image copies take 10 to 15 minutes) | vnet-saat, the CLI | Covered by the free account’s B2ats v2 hours, plus a few US cents for image storage | Capture an image to a gallery, run a zonal scale set from it, roll out a change, and read a quota error |
What it is, in one line
A VM scale set runs many identical VMs from one image and one model, and it grows or shrinks the group for you.
In Simple Words
The school uniform tailor
A tailor makes one perfect school uniform and keeps the pattern, so when 50 new students join, he cuts 50 copies from that pattern instead of measuring every child from scratch. The pattern is the image, the labelled cupboard where patterns are kept (“version 1”, “version 2”) is the gallery, and the class wearing the uniforms is the scale set.
If the school changes the button colour, the tailor updates the pattern, but the uniforms the kids are already wearing don’t change on their own; somebody has to swap them. That’s the first ticket you’ll fix today.
Engineer's View
Images, galleries and scale sets in detail
- Generalized image: the machine-specific bits (users, host keys, hostname) are stripped out with
waagent -deprovision+useron Linux or Sysprep on Windows, so every new VM gets a fresh identity. The source VM can’t be used again after this. - Specialized image: an exact copy with the same users and settings, which is fine for cloning one server but not for fleets.
- Azure Compute Gallery: stores image definitions (publisher, offer, SKU, OS, generation, security type) and numbered image versions (1.0.0, 1.0.1). You can copy versions to other regions and share them with other subscriptions. Gallery names can have letters, numbers, underscores and periods, but no hyphens.
- Managed images are the older, single-region way of doing this, so use the gallery for anything new.
- Orchestration mode: Flexible (the CLI default, recommended for new work, normal VM objects, sizes can mix) or Uniform (identical instances managed through the scale set API; still common, and the easiest place to learn model updates).
- Model and upgrade policy: the scale set keeps a model (image, size, extensions). When you change it, Manual waits for you to update the instances, Automatic updates all of them at once, and Rolling works through them in batches with health checks.
- Overprovisioning (Uniform): Azure briefly creates a few extra instances and deletes the slowest ones, which is why instance IDs can skip numbers. You don’t pay for the extras.
- Autoscale: rules based on metrics such as Percentage CPU, with a minimum, a maximum and a default count, plus a cool-down that’s 5 minutes by default.
- Quotas: each scale-out needs vCPU quota, both for the VM family and for the region in total, and a free account has small limits.
How it works, step by step
Going from one built server to a fleet takes four moves:
- Build: create build01 and install the app on it, using cloud-init here.
- Generalize: deprovision inside Linux, deallocate the VM, and then mark it generalized with
az vm generalize. - Capture: create image version 1.0.0 in the gallery from build01, and delete build01 afterwards.
- Deploy: create the scale set from that image version, spread it across zones and add the autoscale rules.
Later changes go down the same path. A new app release becomes image version 1.0.1, you point the scale set model at it, and the upgrade policy decides when the running instances move over.
No instance should ever be special. If you SSH in and fix something by hand, the next scale-out or reimage wipes it, so every fix has to go into the image or the model.
Hands-on lab: Azure VM scale sets from a gallery image
Before you run any command, double-check it
Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.
Load the network IDs and create the lab group:
$v = Get-Content C:\azure-lab\vnet-saat.json | ConvertFrom-Json
az group create --name rg-saat-l20 --tags course=saatvedha-azure lesson=20 -o none1Build the source VM
Save the cloud-init file and then create build01 (it takes about two minutes):
$y = @'
#cloud-config
write_files:
- path: /var/www/index.html
content: |
<h1>img-web 1.0.0</h1>
- path: /etc/systemd/system/saat-web.service
content: |
[Unit]
Description=SaatVedha lab web page
After=network-online.target
[Service]
ExecStart=/usr/bin/python3 -m http.server 80 --directory /var/www
Restart=always
[Install]
WantedBy=multi-user.target
runcmd:
- systemctl daemon-reload
- systemctl enable --now saat-web
'@
[IO.File]::WriteAllText('C:\azure-lab\img-web-init.yaml', $y.Replace("`r`n", "`n"))
az vm create --resource-group rg-saat-l20 --name build01 --image Canonical:ubuntu-24_04-lts:server:latest --size Standard_B2ats_v2 --subnet $v.'snet-web' --public-ip-address '""' --nsg '""' --admin-username azureuser --generate-ssh-keys --custom-data C:\azure-lab\img-web-init.yaml --tags course=saatvedha-azure lesson=20 -o noneCheck that the page is being served:
az vm run-command invoke --resource-group rg-saat-l20 --name build01 --command-id RunShellScript --scripts 'cloud-init status --wait; curl -s localhost' --query "value[0].message" -o tsvYou should see this:
Enable succeeded:
[stdout]
status: done
<h1>img-web 1.0.0</h1>
[stderr]2Generalize it
Run this:
az vm run-command invoke --resource-group rg-saat-l20 --name build01 --command-id RunShellScript --scripts 'waagent -deprovision+user -force' -o none
az vm deallocate --resource-group rg-saat-l20 --name build01
az vm generalize --resource-group rg-saat-l20 --name build01Deprovisioning removes azureuser, the SSH host keys and the hostname. If the first command reports a timeout, carry on, because the deprovision still ran. After this build01 can never start again; its only job now is to be copied.
3Create the gallery, image definition and version 1.0.0
Run this (the version takes 10 to 15 minutes):
az sig create --resource-group rg-saat-l20 --gallery-name galsaat --tags course=saatvedha-azure lesson=20 -o none
az sig image-definition create --resource-group rg-saat-l20 --gallery-name galsaat --gallery-image-definition img-web --publisher SaatVedha --offer web --sku ubuntu2404 --os-type Linux --os-state Generalized -o none
$vmId = az vm show --resource-group rg-saat-l20 --name build01 --query id -o tsv
az sig image-version create --resource-group rg-saat-l20 --gallery-name galsaat --gallery-image-definition img-web --gallery-image-version 1.0.0 --virtual-machine $vmId --replica-count 1 --storage-account-type Standard_LRS --tags course=saatvedha-azure lesson=20 -o none
az sig image-version list --resource-group rg-saat-l20 --gallery-name galsaat --gallery-image-definition img-web --query "[].{version:name, state:provisioningState, regions:join(', ', publishingProfile.targetRegions[].name)}" -o table
az vm delete --resource-group rg-saat-l20 --name build01 --yesYou should see this:
Version State Regions
--------- --------- -------------
1.0.0 Succeeded Central IndiaThe CLI made the definition Gen2 with Trusted Launch support, to match the Ubuntu 24.04 build VM.
4Create the scale set across two zones
Run this (about three minutes):
$img = az sig image-version show --resource-group rg-saat-l20 --gallery-name galsaat --gallery-image-definition img-web --gallery-image-version 1.0.0 --query id -o tsv
az vmss create --resource-group rg-saat-l20 --name vmss-web --image $img --vm-sku Standard_B2ats_v2 --instance-count 2 --zones 1 2 --orchestration-mode Uniform --upgrade-policy-mode Manual --subnet $v.'snet-web' --lb '""' --admin-username azureuser --generate-ssh-keys --tags course=saatvedha-azure lesson=20 -o none
az vmss list-instances --resource-group rg-saat-l20 --name vmss-web --query "[].{id:instanceId, name:name, zone:zones[0], latest:latestModelApplied}" -o tableYou should see something like this:
Id Name Zone Latest
---- ---------- ------ --------
0 vmss-web_0 1 True
2 vmss-web_2 2 TrueDon’t worry if the IDs skip a number, that’s overprovisioning. You’ve got one instance in each zone, both on the latest model. There’s no load balancer yet; that comes in Lesson 51.
5Check both copies serve the page
Run this:
$ids = az vmss list-instances --resource-group rg-saat-l20 --name vmss-web --query "[].instanceId" -o tsv
foreach ($id in $ids) { az vmss run-command invoke --resource-group rg-saat-l20 --name vmss-web --instance-id $id --command-id RunShellScript --scripts 'hostname; curl -s localhost' --query "value[0].message" -o tsv }You should see something like this:
Enable succeeded:
[stdout]
vmss-web000000
<h1>img-web 1.0.0</h1>
[stderr]
Enable succeeded:
[stdout]
vmss-web000002
<h1>img-web 1.0.0</h1>
[stderr]Two different hostnames serving the same app, and nothing was installed by hand.
6Add autoscale rules
Run this:
az monitor autoscale create --resource-group rg-saat-l20 --resource vmss-web --resource-type Microsoft.Compute/virtualMachineScaleSets --name as-vmss-web --min-count 1 --max-count 2 --count 2 -o none
az monitor autoscale rule create --resource-group rg-saat-l20 --autoscale-name as-vmss-web --condition "Percentage CPU > 70 avg 5m" --scale out 1 -o none
az monitor autoscale rule create --resource-group rg-saat-l20 --autoscale-name as-vmss-web --condition "Percentage CPU < 25 avg 10m" --scale in 1 -o none
az monitor autoscale rule list --resource-group rg-saat-l20 --autoscale-name as-vmss-web --query "[].{metric:metricTrigger.metricName, op:metricTrigger.operator, threshold:metricTrigger.threshold, action:scaleAction.direction}" -o tableYou should see this:
Metric Op Threshold Action
-------------- ----------- ----------- --------
Percentage CPU GreaterThan 70.0 Increase
Percentage CPU LessThan 25.0 DecreaseSetting the maximum to 2 keeps the lab inside your quota. With the CPU idle, autoscale may scale in to 1 after about 10 minutes, which just means the rule is working. In production you’d keep the scale-in threshold well below scale-out so the set doesn’t keep flapping between sizes.

✅ Checkpoint: Image version 1.0.0 is in galsaat, vmss-web runs copies in zones 1 and 2, and both rules are listed.
Break It, Then Fix It
Teams that run scale sets see both of these tickets every week.
1Break it: change the scale set, nothing happens
Roll out a small fix using the Custom Script extension. The settings go in a file so PowerShell can’t eat the quotes:
Set-Content -Path C:\azure-lab\cse.json -Value '{"commandToExecute": "echo img-web 1.0.0 plus fix 1 > /var/www/index.html"}'
$ids = az vmss list-instances --resource-group rg-saat-l20 --name vmss-web --query "[].instanceId" -o tsv
az vmss extension set --resource-group rg-saat-l20 --vmss-name vmss-web --name CustomScript --publisher Microsoft.Azure.Extensions --version 2.1 --settings '@C:\azure-lab\cse.json' -o none
az vmss list-instances --resource-group rg-saat-l20 --name vmss-web --query "[].{id:instanceId, latest:latestModelApplied}" -o table
foreach ($id in $ids) { az vmss run-command invoke --resource-group rg-saat-l20 --name vmss-web --instance-id $id --command-id RunShellScript --scripts 'curl -s localhost' --query "value[0].message" -o tsv }You’ll see something like this:
Id Latest
---- --------
0 False
2 False
Enable succeeded:
[stdout]
<h1>img-web 1.0.0</h1>
...The command “succeeded” and yet the page hasn’t changed. That’s because the fix went into the scale set model, and with upgrade policy Manual no instance picks up a new model until you tell it to. The clue is Latest = False.
Fix it: update the instances. In production you’d do one or a few at a time:
az vmss update-instances --resource-group rg-saat-l20 --name vmss-web --instance-ids '*'
az vmss list-instances --resource-group rg-saat-l20 --name vmss-web --query "[].{id:instanceId, latest:latestModelApplied}" -o table
foreach ($id in $ids) { az vmss run-command invoke --resource-group rg-saat-l20 --name vmss-web --instance-id $id --command-id RunShellScript --scripts 'curl -s localhost' --query "value[0].message" -o tsv }You should see something like this:
Id Latest
---- --------
0 True
2 True
Enable succeeded:
[stdout]
img-web 1.0.0 plus fix 1
...If some instances are missing from the list now, autoscale has scaled in, and that’s fine. For real releases, bake the fix into image version 1.0.1 and use a Rolling policy with health checks, so a bad release stops after the first batch.
2Break it: the scale set won’t grow
Check your quota for this VM family and for the region as a whole:
$fam = az vm list-skus --location centralindia --size Standard_B2ats_v2 --query "[0].family" -o tsv
az vm list-usage --location centralindia --query "[?name.value=='$fam' || name.value=='cores'].{name:localName, current:currentValue, limit:limit}" -o tableYou should see something like this (your numbers may differ):
Name Current Limit
------------------------------- --------- -------
Total Regional vCPUs 4 4
Standard Basv2 Family vCPUs 4 4Now ask for more instances than the limit allows. Remove autoscale first, since it would fight a manual change anyway:
az monitor autoscale delete --resource-group rg-saat-l20 --name as-vmss-web
$limit = az vm list-usage --location centralindia --query "min([?name.value=='$fam' || name.value=='cores'].limit)" -o tsv
$cap = [math]::Floor([int]$limit / 2) + 1
if ($cap -le 6) { az vmss scale --resource-group rg-saat-l20 --name vmss-web --new-capacity $cap } else { "Your limit is $limit, so skip this step rather than create $cap VMs." }You’ll get an error like this:
(OperationNotAllowed) Operation could not be completed as it results in exceeding approved standardBasv2Family Cores quota. Additional details - Deployment Model: Resource Manager, Location: centralindia, Current Limit: 4, Current Usage: 4, Additional Required: 2, (Minimum) New Limit Required: 6. Submit a request for Quota increase ...
Code: OperationNotAllowedIf your limit happens to be high, the safety check stops the command so you can’t create a big set by accident. The error tells you which quota it is, the current limit and the new limit you need to ask for. Autoscale hits the same wall without any noise: the failure shows up in its activity log while the set stays small through a traffic spike.
Fix it: ask for a quota increase (in the portal, Quotas and then Compute) before you need it, or scale within the limit. For this lab, stay within it and then clean up:
az vmss scale --resource-group rg-saat-l20 --name vmss-web --new-capacity 1
az group delete --name rg-saat-l20 --yes
C:\azure-lab\Find-LabResources.ps1 -Lesson 20You should see this:
Nothing tagged course=saatvedha-azure is left.
✅ Checkpoint: You rolled out a model change with update-instances, read a quota error, and nothing from Lesson 20 is left.
Deleting the group removes the gallery and image as well. Free accounts often can’t raise quota until they’re upgraded to pay-as-you-go.
This happened at work
Sale day, and the web farm stopped at 10
An online electronics shop ran its storefront on a scale set that could autoscale from 4 to 30 instances. On the first morning of a festival sale CPU went to 95% and pages were taking 20 seconds to load, and the autoscale chart showed it trying to scale out every five minutes and failing each time.
The answer was sitting in the activity log. The family quota was 40 vCPUs, and 10 instances of a 4 vCPU size had used up all of it. When the maximum went from 10 to 30 the month before, nobody had thought to raise the quota.
What they changed: an emergency quota request got approved within the hour. After the sale the team added a check to every scaling change, so max instances times vCPUs has to fit inside the quota with 20% to spare, and quota usage now raises an alert at 80%.
Common mistakes and troubleshooting
| Mistake | What you see | What to do |
|---|---|---|
| Changing the model with Manual upgrade policy | latestModelApplied False, old behaviour | Run update-instances, or switch to Rolling. |
| Max instances above quota | Scale-out fails; OperationNotAllowed in activity log | Check list-usage and request quota in advance. |
| Fixing an instance by hand | Fix disappears on the next scale-out or reimage | Put the fix into the image or the model. |
| Capturing without generalizing | Image version fails, or clones share identity | Deprovision, deallocate, then az vm generalize. |
| Hyphen in a gallery name | Create fails on the name | Stick to letters, numbers, underscores and periods. |
| Scale-in threshold close to scale-out | Instance count flaps all day | Leave a wide gap, for example 70% out and 25% in. |
| Manual scale with autoscale on | Count snaps back | Change the autoscale min, max or default count instead. |
Interview questions
Click a question to open it. Each one is phrased the way an interviewer would ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.
Fresher level
1. What is a VM scale set?
Why they ask this: It’s the basic definition.
How you might answer: It’s a group of identical VMs built from one image and one model and managed together. It can spread them over zones, and with autoscale rules it grows or shrinks the group on its own.
2. What’s the difference between a generalized and a specialized image?
Why they ask this: They want to know when you’d use each one.
How you might answer: A generalized image has the machine-specific data removed, so every new VM gets its own identity, whereas a specialized image is an exact copy with the same users and settings. For fleets and scale sets you use generalized images.
3. What is an Azure Compute Gallery?
Why they ask this: They’re checking that you know the current image service.
How you might answer: It’s where you store and version images. It keeps image definitions and numbered versions, copies them to other regions and shares them with other subscriptions, and for most work it has replaced single-region managed images.
2–5 years experience
4. You changed a scale set’s extension but instances behave the same. Why?
Why they ask this: It’s one of the most common operational tickets.
How you might answer: The change only updated the model, and with upgrade policy Manual the instances stay on the old model until you run update-instances. I’d check latestModelApplied, update one instance and test it, and then roll out to the rest.
5. Autoscale is set to 30 but the set is stuck at 10 during a spike. What do you check?
Why they ask this: They want to see that you know about quota and the activity log.
How you might answer: I’d look at the autoscale run history and the activity log for failed scale operations, then check vCPU quota for the family and the region with az vm list-usage. Nine times out of ten it’s quota. I’d also make sure the subnet has enough free IP addresses.
6. Flexible or Uniform orchestration: which would you choose?
Why they ask this: They want to know you’re up to date with the guidance.
How you might answer: For new work I’d use Flexible. It’s the default and recommended mode, the instances are normal VMs, and you can mix sizes. Uniform is still around for very large sets of identical instances and some older tools, so I’d only choose it if something specifically needed it.
Senior level
7. How would you roll out a new app version to a scale set safely?
Why they ask this: They want a release process rather than one command.
How you might answer: I’d build image version 1.0.1 in a pipeline and test it, then point the model at it using a Rolling upgrade policy with application health checks. Rolling goes one batch at a time and stops if health checks fail, and I’d keep 1.0.0 in the gallery so rolling back is quick.
8. How do you design autoscale rules that don’t flap?
Why they ask this: They want practical tuning experience.
How you might answer: Keep a wide gap between the scale-out and scale-in thresholds, use longer windows for scale-in, set cool-downs and a sensible default count. My habit is to scale out fast and in slowly, and add a schedule-based profile for the busy hours we already know about.
9. What would you include in an image pipeline?
Why they ask this: They’re checking how you govern images.
How you might answer: It starts from a supported marketplace image, applies OS updates and hardening, installs the agents and the app, runs tests, then generalizes and publishes a new version to the gallery with replicas in the regions we use. Old versions get an end-of-life date, and the scale sets are moved forward on a schedule.
Quick quiz
Q1. What does generalizing a Linux VM remove?
- The OS disk
- Users, host keys and hostname
- The network card
- The image definition
Show answer
B — Generalizing strips machine-specific identity so each copy is unique.
Q2. A scale set uses upgrade policy Manual. After a model change, instances:
- Update at once
- Update in batches
- Keep the old model until you update them
- Are deleted
Show answer
C — Manual means nothing changes until you run update-instances.
Q3. Which property shows an instance runs the current model?
- provisioningState
- latestModelApplied
- powerState
- zones
Show answer
B — latestModelApplied is False until the instance is updated.
Q4. Scale-out fails with OperationNotAllowed and “Cores quota”. What do you do?
- Delete the gallery
- Request a quota increase or scale within it
- Change the zone
- Restart autoscale
Show answer
B — The error names the quota and the new limit needed.
Q5. Which is a valid gallery name?
- gal-saat
- gal saat
- galsaat
- gal/saat
Show answer
C — Letters, numbers, underscores and periods only.
Quick recap
You’ve built a small image pipeline and run a fleet from it.
- Generalize, capture to a gallery, then deploy many copies from a version.
- A scale set runs from a model, and the upgrade policy decides when instances pick up changes.
- latestModelApplied tells you which instances are behind.
- Autoscale needs vCPU quota, so check list-usage before you raise the maximum.
- Don’t fix instances by hand; fix the image or the model.
Next lesson
Lesson 21: Azure storage accounts and redundancy → Next you’ll create a storage account and see how LRS, ZRS and GRS keep your data safe.
Further reading: Azure VM scale sets
Want to go deeper into Azure VM scale sets? See Microsoft’s Virtual Machine Scale Sets overview and Store and share images in an Azure Compute Gallery. You can also see the full plan for this course on the Azure Cloud Administration course page.
