Microsoft Azure Cloud
Andrew Posted on 12:35 pm

Using Azure Spot Instances

Today we take a look at Spot VMs in Azure and what it’s all about. Spot VMs allow you to take advantage of unused capacity on Azure VM hosts at a significant cost savings; but there is a catch. Your VMs can be evicted if Azure needs the capacity back. This style of VM hosting can be used for low-priority workloads and managed using a few different settings. Let’s explore Spot VMs in Azure together!

First, let’s understand how this all works. Basically, using Spot Instances we can access unused resources on hosts in Azure and save money by using these little slices of untapped computing power….but we have to keep in mind that if Azure wants it back we get 30 seconds notice to finish running jobs and shut down before the eviction.

You can use Azure Scheduled Events to notify you of evictions.

There are some option you can configure:

OptionOutcome
Max price is set to >= the current price.VM is deployed if capacity and quota are available.
Max price is set to < the current price.The VM is not deployed. You will get an error message that the max price needs to be >= current price.
Restarting a stop/deallocate VM if the max price is >= the current priceIf there is capacity and quota, then the VM is deployed.
Restarting a stop/deallocate VM if the max price is < the current priceYou will get an error message that the max price needs to be >= current price.
Price for the VM has gone up and is now > the max price.The VM gets evicted. You get a 30s notification before actual eviction.
After eviction the price for the VM goes back to being < the max price.The VM will not be automatically re-started. You can restart the VM yourself, and it will be charged at the current price.
If the max price is set to -1The VM will not be evicted for pricing reasons. The max price will be the current price, up to the price for standard VMs. You will never be charged above the standard price.
Changing the max priceYou need to deallocate the VM to change the max price. Deallocate the VM, set a new max price, then update the VM.
Source: Microsoft Docs

There are some limitations with Spot VMs — not supported is:

  • B-Series
  • Promo versions of any size
  • Spot VM Instances are not supported in Microsoft Azure China 21Vianet

Additionally, the following offer types are supported:

  • Enterprise Agreement
  • Pay-as-you-go
  • Sponsored
  • CSP / Cloud Service Provider (Contact your partner for details)

Pricing information is available for reference but pricing for Spot VMs is variable, based on region and SKU. For more information, see VM pricing for Linux and Windows.

If you are looking to optimize costs for your production environment, Spot VM Instances can help for temporary and managed resources; but I would suggest looking at reserved instances instead for servers that use static loads such as a file server. You can reference cost estimates for Spot, 3 and 1 year reserved, and Pay as you Go costs — and — toggle Azure Hybrid Benefit on/off (bring your own licenses) in this great Pricing tool here.

How to Create an Azure Spot VM Instance

Ok, finally we can reference some hands-on now that we’ve covered all the groundwork details!

Head to your testing subscription at https://portal.azure.com and get logged in.

Now, we’ll create a VM manually here today so let’s head to the Virtual Machines blade. Next let’s +Add a Virtual Machine:

Now we’ll need to select some options here:

Since we already understand all the details from the top half of this article (wink wink!) let’s just breeze through this a bit. We’ll select Spot Instance > Yes.

Next we’ll set the Eviction type to Capacity Only and the Eviction Policy to Stop/Deallocate.

Our VM type today will be a D2s_v3 and as you can see the pricing is quite excellent.

Note the little link at the bottom of your Create a Virtual Machine blade — View Pricing History and Compare Prices in Nearby Regions — this little gem will show you other nearby regions with their average pricing over time. It’s a great little reporting tool baked right in for us here! I was able to see that by moving to Canada Central from North Central US I could save even more money and optimize costs in Azure by changing regions. Further, we get to see the eviction rate for each nearby region shown, this is amazing! Again, Canada Central was a better choice.

I would also like to point out that if we were to select the option “Price or Capacity” instead of “Capacity Only” in the Eviction Type, we would be able to set a maximum price on this new blade.

Go and enjoy testing your Azure Spot VM Instances! It’s another great way that we can help to optimize our operational costs and increase the flexibility in using different ways to manage our workloads.