Bird
Raised Fist0
Azurecloud~30 mins

Spot VMs for cost savings in Azure - Mini Project: Build & Apply

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
Spot VMs for cost savings
📖 Scenario: You are managing cloud resources for a small company. You want to save money by using Spot Virtual Machines (VMs) in Azure. Spot VMs let you use unused capacity at a lower price but can be evicted when Azure needs the resources back.Your task is to create an Azure Resource Manager (ARM) template that deploys a Spot VM with specific settings to save costs.
🎯 Goal: Build an ARM template that deploys a Spot VM with eviction policy set to Deallocate, and a maximum price set to save costs.
📋 What You'll Learn
Create a resource group variable
Define a VM resource with Spot VM priority
Set eviction policy to Deallocate
Set maximum price for the Spot VM
💡 Why This Matters
🌍 Real World
Spot VMs help companies save money by using unused cloud capacity at a lower price, suitable for flexible workloads.
💼 Career
Cloud engineers often configure Spot VMs to optimize costs while managing eviction risks in production or development environments.
Progress0 / 4 steps
1
Create resource group and basic VM variables
Create a variable called resourceGroupName and set it to "myResourceGroup". Then create a variable called vmName and set it to "mySpotVM".
Azure
Hint

Use var to declare variables and assign the exact string values.

2
Add Spot VM priority and eviction policy variables
Add a variable called priority and set it to "Spot". Then add a variable called evictionPolicy and set it to "Deallocate".
Azure
Hint

Spot VMs use priority set to "Spot" and eviction policy can be "Deallocate".

3
Add maximum price variable for Spot VM
Add a variable called maxPrice and set it to -1 to allow the Spot VM to use the current market price.
Azure
Hint

Setting maxPrice to -1 means the VM will pay up to the current Spot price.

4
Define the Spot VM resource with priority, eviction policy, and max price
Create a JSON object called spotVMResource representing the VM resource. Include the priority, evictionPolicy, and maxPrice properties in the properties section of the VM resource. Use the variables vmName, priority, evictionPolicy, and maxPrice in the object.
Azure
Hint

Use the variables inside the JSON object for the VM resource. Include priority, evictionPolicy, and maxPrice in the correct places.

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