Reading Time: 3 minutes

Today it was announced the general availability of Azure Spot Virtual Machines (VMs). Azure Spot VMs provide access to unused Azure compute capacity at deep discounts. Spot pricing is available on single VMs in addition to VM scale sets (VMSS). This enables you to deploy a broader variety of workloads on Azure while enjoying access to discounted pricing compared to pay-as-you-go rates. Spot VMs offer the same characteristics as a pay-as-you-go virtual machine, the differences being pricing and evictions. Spot VMs can be evicted at any time if Azure needs capacity.

The workloads that are ideally suited to run on Spot VMs include, but are not necessarily limited to, the following:

  • Batch jobs.
  • Workloads that can sustain or recover from interruptions.
  • Development and test.
  • Stateless applications that can use Spot VMs to scale out, opportunistically saving cost.
  • Short-lived jobs which can easily be run again if the VM is evicted.

Spot VMs have replaced the preview of Azure low-priority VMs on scale sets. Eligible low-priority VMs have been automatically transitioned over to Spot VMs.

Deploying an Azure Spot VM

It is no different than creating a normal Azure VM, you just choose “Yes” under the option “Azure Spot Instance” and then 2 more option appears: “Eviction type” and “Eviction policy”.

If you are using ARM Templates to deploy your VMs the only difference is the following set of properties of the VM:

ARM template property set for deploying an Azure Spot VM

Special Quota for Azure Sport VMs or VMSS are also rolled out along with the announcement today, for better management and flexibility side by side with our PAYG subscriptions.

Handling evictions

Azure will try to keep your Spot VM running and minimize evictions, but your workload should be prepared to handle evictions as the runtime for an Azure Spot VMs and VMSS instances are not guaranteed.

Important note:

If you’re running a single Spot VM, the VM is deallocated, and no additional VM-related charges are incurred after deallocation. However, other resources (such as disk or network) continue to run and accrue charges.

If you’re running Spot VMs on VMSS, it depends on the eviction policy that you select. If the eviction policy is set to Deallocate, only the VM is deallocated, and no VM-associated charges are incurred. However, other resources (such as disk or network) continue to run and accrue charges. Conversely, if the eviction policy is set to Delete, the VM and all associated resources are deleted.

Best practices

Here are some effective ways to best utilize Azure Spot VMs:

  • For long-running operations, try to create checkpoints so that you can restart your workload from a previously known checkpoint to handle evictions and save time.
  • In scale-out scenarios, to save costs, you can have two VMSS, where one has regular VMs and the other has Spot VMs. You can put both in the same load balancer to opportunistically scale-out.
  • Listen to eviction notifications in the VM to get notified when your VM is about to be evicted.
  • If you are willing to pay up to pay-as-you-go prices then use Eviction type to Capacity Eviction only, in the API provide -1 as max price as Azure never charges you more than the Spot VM price.
  • To handle evictions, build a retry logic to redeploy VMs. If you do not require a specific VM series and size, then try to deploy a different size that matches your workload needs.
  • While deploying VMSS, select max spread in the portal management tab or FD==1 in the API to find capacity in a zone or region.

Learn more about the Azure Spot Virtual Machine and VMSS here. Windows pricing here and Linux pricing here.

Cheers!