Microsoft Azure now has Spot Instances in Preview.  These are effectively the same as the AWS Spot Instances on EC2.  The provide an excellent way to reduce costs for non-mission critical processes.

Azure effectively auctions their excess capacity.  The price does fluctuate and availability changes.  If the price exceeds your specified maximum price or there is insufficient capacity, your VM will automatically shut down.  So this is not for mission critical processes, but so far, my test VMs have been running continuously for several weeks.

There is no direct way to convert an existing VM to a Spot Instance VM.  The Portal does not provide any options.  The Azure CLI has a method to allow you to update the VM priority (Spot vs Regular), but, as of now, it specifically disallows converting an existing VM from Regular to Spot or from Spot to Regular – not the most helpful update method.

WARNING: this will result in downtime and could be destructive.  Ensure that you have appropriate backups and can tolerate the downtime.  Using Spot Instances on processes that cannot tolerate downtime is not advised without extensive automation.

Steps:

  1. Ensure you are on the most recent version of the Azure CLI.  Older version do not support Spot Instances.
  2. Delete the existing VM, while retaining the IP, NIC, OS Disk, and any Data Disks.
  3. Re-create the VM using the following CLI template:
az vm create --name {VM Name} 
  --resource-group {Resource Group Name} 
  --subscription {Subscription Id} \
  --os-type linux \
  --attach-data-disks {Existing Data Disk Names (if any)} \
  --attach-os-disk {Existing OS Disk Name} \
  --size Standard_D2s_v3 \
  --location eastus2 \
  --nics {Network Interface Name} \
  --max-price -1 \
  --priority Spot

You may want to update the os-type, size, location, and max price.  A max-price of -1 means that your VM not be shut down due to cost, only due to capacity shortages.

To convert back to a Regular VM, follow the same steps, which set --priority to Regular instead of Spot.

Ideally, you would automate Spot Instance creation to add capacity as needed.

You're all set and you're now saving money on your non-critical servers.

Thank you for reading!  Let me know your thoughts or if you have any questions!