Bird
Raised Fist0
Azurecloud~10 mins

Spot VMs for cost savings in Azure - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Spot VMs for cost savings
Request Spot VM
Azure checks capacity
Capacity available?
NoSpot VM denied
Spot VM allocated
Run workload
Preemption event?
YesVM evicted
Workload stops
Workload completes
End
The flow shows requesting a Spot VM, Azure checking capacity, allocating if available, running workload, and possible eviction if capacity is needed.
Execution Sample
Azure
az vm create --name mySpotVM --resource-group myRG --image UbuntuLTS --priority Spot --max-price -1
This command creates a Spot VM in Azure with no max price limit, allowing cost savings but possible eviction.
Process Table
StepActionAzure ResponseVM StateNotes
1Request Spot VM creationCheck capacityPendingAzure checks if Spot capacity is available
2Capacity available?YesAllocatedSpot VM is allocated and starts running
3Run workloadRunningRunningWorkload runs on Spot VM
4Preemption event occursEviction noticeEvictedAzure needs capacity, evicts Spot VM
5Workload stopsVM deallocatedStoppedSpot VM is stopped, workload interrupted
6Request Spot VM creationCheck capacityPendingIf retried, process repeats
7Capacity available?NoDeniedSpot VM creation denied due to no capacity
💡 Execution stops when Spot VM is evicted or creation is denied due to capacity.
Status Tracker
VariableStartAfter Step 2After Step 4After Step 5After Step 7
VM StateNoneAllocatedEvictedStoppedDenied
Azure CapacityUnknownAvailableNeeded ElsewhereNeeded ElsewhereUnavailable
Key Moments - 3 Insights
Why can a Spot VM be evicted even if my workload is running?
Because Azure can reclaim Spot VMs anytime when it needs capacity, as shown in execution_table step 4 where a preemption event causes eviction.
What happens if there is no capacity available when requesting a Spot VM?
The Spot VM creation is denied immediately, as shown in execution_table step 7 where capacity is unavailable and VM state is Denied.
Does setting max-price to -1 guarantee my Spot VM will never be evicted?
No, max-price -1 means you accept any price, but eviction depends on Azure capacity needs, not price, as seen in the eviction event in step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the VM State after Azure confirms capacity is available?
AAllocated
BPending
CEvicted
DDenied
💡 Hint
Check execution_table row 2 under VM State column.
At which step does the Spot VM get evicted due to capacity needs?
AStep 3
BStep 4
CStep 6
DStep 7
💡 Hint
Look for 'Preemption event occurs' in execution_table.
If Azure capacity is not available, what is the VM State shown in variable_tracker after that step?
AAllocated
BRunning
CDenied
DStopped
💡 Hint
See variable_tracker column 'After Step 7' for VM State.
Concept Snapshot
Spot VMs are low-cost Azure VMs that can be evicted anytime.
Request Spot VM with priority Spot and optional max-price.
Azure allocates if capacity is free; otherwise denies.
Workloads run until eviction (preemption) occurs.
Best for interruptible, flexible workloads to save cost.
Full Transcript
Spot VMs in Azure are special virtual machines offered at a lower price because Azure can reclaim them anytime when it needs capacity. When you request a Spot VM, Azure checks if there is enough capacity. If yes, it allocates the VM and your workload runs. However, if Azure needs the capacity back, it sends an eviction notice and stops the VM, interrupting your workload. If there is no capacity at request time, the Spot VM creation is denied immediately. Setting max-price to -1 means you accept any price, but eviction depends on capacity, not price. Spot VMs are best for workloads that can handle interruptions and want to save money.

Practice

(1/5)
1. What is the main benefit of using Azure Spot VMs?
easy
A. They automatically scale without any configuration.
B. They guarantee 100% uptime for critical applications.
C. They provide cheaper compute by using spare capacity.
D. They offer unlimited storage space for virtual machines.

Solution

  1. Step 1: Understand Spot VM purpose

    Spot VMs use unused cloud capacity to offer lower prices.
  2. Step 2: Compare benefits

    Unlike regular VMs, Spot VMs are cheaper but can be evicted when capacity is needed.
  3. Final Answer:

    They provide cheaper compute by using spare capacity. -> Option C
  4. Quick Check:

    Spot VMs = cheaper compute [OK]
Hint: Spot VMs save cost by using spare capacity [OK]
Common Mistakes:
  • Thinking Spot VMs guarantee uptime
  • Confusing Spot VMs with auto-scaling
  • Assuming Spot VMs provide extra storage
2. Which of the following is the correct way to set a Spot VM priority in Azure CLI?
easy
A. az vm create --priority High
B. az vm create --priority Spot
C. az vm create --spot-priority true
D. az vm create --enable-spot

Solution

  1. Step 1: Recall Azure CLI syntax for Spot VMs

    The correct parameter to set Spot VM priority is --priority Spot.
  2. Step 2: Evaluate options

    The other options use incorrect or non-existent flags.
  3. Final Answer:

    az vm create --priority Spot -> Option B
  4. Quick Check:

    Spot VM priority flag = --priority Spot [OK]
Hint: Use --priority Spot to create Spot VMs [OK]
Common Mistakes:
  • Using incorrect flags like --spot-priority
  • Setting priority to High instead of Spot
  • Assuming --enable-spot is valid
3. Consider this Azure CLI command to create a Spot VM:
az vm create --name mySpotVM --image UbuntuLTS --priority Spot --max-price 0.05
What happens if the current Spot price exceeds 0.05 USD/hour?
medium
A. The VM is converted to a regular VM automatically.
B. The VM continues running at the higher price.
C. The VM price is capped at 0.05 USD/hour but runs normally.
D. The VM is evicted (stopped) automatically.

Solution

  1. Step 1: Understand max-price setting

    The max-price limits the Spot VM cost; if price rises above it, eviction occurs.
  2. Step 2: Analyze behavior when price exceeds max-price

    Spot VMs are stopped or deallocated automatically when price exceeds max-price.
  3. Final Answer:

    The VM is evicted (stopped) automatically. -> Option D
  4. Quick Check:

    Price > max-price = VM eviction [OK]
Hint: Spot VM stops if price goes above max-price [OK]
Common Mistakes:
  • Thinking VM keeps running at higher price
  • Assuming price is capped automatically
  • Believing VM converts to regular VM
4. You tried to create a Spot VM with this command:
az vm create --name testVM --image UbuntuLTS --priority Spot --max-price -2
What is the issue with this command?
medium
A. max-price cannot be negative; it causes an error.
B. Priority Spot is invalid syntax.
C. Image UbuntuLTS is not supported for Spot VMs.
D. VM name testVM is reserved and cannot be used.

Solution

  1. Step 1: Check max-price parameter rules

    max-price must be greater than or equal to -1; other negative values are invalid.
  2. Step 2: Identify error cause

    Using -2 for max-price causes a validation error during VM creation.
  3. Final Answer:

    max-price cannot be negative; it causes an error. -> Option A
  4. Quick Check:

    max-price < -1 = error [OK]
Hint: max-price must be >= -1 [OK]
Common Mistakes:
  • Using negative max-price values
  • Thinking Spot priority syntax is wrong
  • Assuming UbuntuLTS is unsupported
5. You want to run a batch job that can pause and resume without losing progress. Which Spot VM configuration helps minimize cost while ensuring the job restarts automatically if evicted?
hard
A. Set VM priority to Spot, max-price to a low value, and enable automatic redeployment.
B. Use regular VMs with high priority and no max-price limit.
C. Set VM priority to Spot with max-price set to -1 to avoid eviction.
D. Use Spot VMs without max-price and disable automatic redeployment.

Solution

  1. Step 1: Choose Spot VM with cost control

    Setting priority to Spot and max-price low saves cost but risks eviction.
  2. Step 2: Enable automatic redeployment

    Automatic redeployment restarts the VM if evicted, ensuring job resumes.
  3. Final Answer:

    Set VM priority to Spot, max-price to a low value, and enable automatic redeployment. -> Option A
  4. Quick Check:

    Spot + max-price + auto redeploy = cost saving + restart [OK]
Hint: Spot + low max-price + auto redeploy = cost + restart [OK]
Common Mistakes:
  • Using negative max-price to avoid eviction
  • Disabling automatic redeployment
  • Choosing regular VMs for cost savings