Read this guide to learn how to scale an Azure Spot discounted VM up or down (vertical resize).
Overview of Azure Spot VMs
When deploying an Azure VM, you may be able to use Azure Spot. This allows you to set the hourly price you want to pay.
Azure Spot offers this option if it has capacity, but when the capacity is required or the price changes due to demand, the VM will either be stopped/deallocated or deleted, depending on the option you chose when you set up the Azure Spot discount.
If you try resizing the VM after creating it, you may not be able to because the maximum price you set for the VM is lower than the price of the new size.
In this situation, you must increase the maximum price you’re willing to pay for the Azure Spot VM. In the remaining part of this guide, I’ll walk you through the steps to stop/deallocate, increase the maximum price offer, and resize it.
Step 1: Get a Quote for the New VM SKU
- Open the VM you want to resize, expand its Availability + scale blade, and navigate to Size. After that, select a new size for the VM and choose Resize.
- The operation should throw an error, including the minimum price you should set. In the screenshot below, I have highlighted the quote (0.04116) I was offered.
If the Resize button is grayed out after selecting any available sizes, you have run out of the Spot discount for that size. See step 2 below for how to proceed.
- Scroll down, expand the Insufficient quota – spot limit section, and click the Request quota next to one of the available VM SKUs.
- Then, on the New Quota Request fly-out window, accept the recommended quota limit or enter another value, and click Submit.
If the request fails, open a support ticket.
Step 2: Stop (Deallocate) the VM
You cannot modify the maximum price offer of an Azure Spot discounted VM while it is running. So, the first step is to stop the VM with the steps below:
- Click the VM’s Overview blade, click Stop, and confirm the operation.
- Confirm that the VM has stopped by clicking the notification icon on the top menu.
Step 3: Increase the Azure Spot VM’s Maximum Price
Now that you have stopped the VM, you can increase the maximum price you want to pay to the price you receive in Step 1 by running the following PowerShell commands.
Run the command via Azure Cloud Shell PowerShell.
#1: Get the VM settings
$VM = Get-AzVM -ResourceGroup "" -Name "VM name>"#2: Set a new Azure Spot maximum price
#Microsoft offered me 0.04116. I set my price at 0.0412 so mine offer is slightly above the quoteUpdate-AzVM -ResourceGroupName "
" -VM $VM -MaxPrice#3: Finally, start the VM
Start-AzVM -ResourceGroupName "
" -Name "VM name>"
Here is a screenshot of the above commands in my Azure Cloud Shell.
Step 4: Scale Up or Down (Resize) the VM
Return to the VM’s Availability + scale > Size blade, select the new size (SKU), and choose Resize.
Monitor the progress of the resize operation via the notification window.
Conclusion
Azure Spot is great for creating discounted VMs for lab and test environments. However, resizing the VM is tricky because of the maximum offer price you set when you created the Spot VM.
The trick is to stop the VM, update the offer maximum price, and then resize the VM.
I explained the steps for completing these tasks in this quick guide, and I hope you found it useful. Let me know your thoughts by responding to our “Was this page helpful?” feedback request below.