Azure Spot VMs Explained

Hello, today I want to talk with you about Azure Spot virtual machines, although this functionality is currently in a public preview, find it a very interesting alternative to save money in dev/test environments but not in production environments of course. And so, in this article, I will show you how to implement this type of virtual machines using Azure PowerShell.

What Microsoft says about Spot VMs: Using Azure Spot VMs allows you to take advantage of our unused capacity at a significant cost savings. At any point in time when Azure needs the capacity back, the Azure infrastructure will evict Spot VMs. VMs can be evicted based on capacity or the max price you set. For virtual machines, the eviction policy is set to Deallocate which moves your evicted VMs to the stopped-deallocated state, allowing you to redeploy the evicted VMs later.

Important characteristics of Azure Spot VMs are:
  • Azure does not offer SLA for this type of VM.
  • If Azure needs the capacity for “pay as you go” workloads, Azure’s infrastructure will evict the Spot virtual machines with a 30-second warning.
  • VMs can be evicted based on capacity or the max price you set.
  • The amount of available capacity can vary based on size, region or time of day.
Features not compatible with ephemeral disks at the time of publication of this article:
  • B-series.
  • Promo versions of any size (like Dv2, NV, NC, H promo sizes).
  • Ephemeral OS disks.
  • Spot VMs cannot be deployed to Microsoft Azure China 21Vianet and Department of Defense (DoD) in the Azure Government region.

Once explained the characteristics of the Azure Spot VM we can begin this tutorial.

Prerequisites

This tutorial assumes that you already have a Microsoft Azure account set up and you have the PowerShell Azure module on your machine installed. If you want to know how to install the PowerShell Azure module on your machine, check out this link.

Assumptions:

  • You created a Resource Group for these resources and the new ones deployed in this tutorial will join that group. If you want to know how to create a Resource Group, check out this link.
  • You already created the necessary Virtual Network and subnet. If you want to know how to create a Virtual Network, check out this link.

The simplest way to get started is to sign in interactively at the command line.

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account.

If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Once you set your default subscription, you’re ready to start.

Set the variables

Here, we define the characteristics of our environment and the resource’s properties.

Set the Spot VM properties

To use an Azure Spot virtual machine, you must use the New-AzVMConfig cmdlet with the following syntax.

-Priority: Specify the priority for the virtual machine. Only supported values are ‘Regular‘, ‘Spot‘ and ‘Low‘.’ Low‘ is deprecated instead used ‘Spot’.

-MaxPrice: Specify a max price you are willing to pay, per hour, for the VM in US dollars (USD), using up to 5 decimals. If you set the value -1, the VM will not be evicted based on the price.

Important: Because it is currently in the public preview, Azure infrastructure will only carry out the eviction of the Spot VMs based on capacity. You can set a maximum price, but it will be ignored. VMs will have a fixed price.

Azure Resource Deployment

In this section, you create and deploy the virtual machine in Microsoft Azure with the features and properties previously declared.

Virtual Machine Deployment

finally, we perform the deployment of the virtual machine, using the New-AzVM cmdlet with the following syntax:

Verify the deployment

You can use the following command to verify the deployment.

Azure Spot VMs

When these VMs are in general availability, I will write a new article about them.

If you want to know more about Azure Spot VMs, check out this link: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/spot-vms