Using Azure Spot Virtual Machines allows you to take advantage of Microsoft Azure unused capacity at a significant cost savings. Spot VMs can be up to 90 percent cheaper than regular (pay-as-you-go) VMs.
But there is shortcoming for the availability. At any point in time when Azure needs the capacity back, the Azure infrastructure will evict Azure Spot Virtual Machines. Azure provides a minimum of 30-seconds advance notice before the actual eviction takes place.
Is there a way we can automatically bring our stopped / evicted VM back online? In this post I am gonna show you how to get your stopped / evicted VM started again in 5 minutes using automation account’s runbook.
In this case, we can enjoy 90% off’s Azure VM and also get availability as much as we can.
Table of Contents
VMs can be evicted based on capacity or the max price you set. When creating an Azure Spot Virtual Machine, you can set the eviction policy to Deallocate (default) or Delete.
The following VM sizes aren’t supported for Azure Spot Virtual Machines:
- Promo versions of any size (like Dv2, NV, NC, H promo sizes)
Azure Spot Virtual Machines can be deployed to any region, except Microsoft Azure operated by 21Vianet.
The biggest challenge is how to start the Spot Instance automatically. We will use alert rule to monitor system and use runbook to trigger a PowerShell script to start stopped VM.
Create VM with A Spot Discount Check
Enable Spot Discount
Make sure there is no infrastructure redundancy selected.
Make eviction policy is stop/deallocate.
Create An Automation Account and Add A Runbook
Search and Create An Automation Account
Import a runbook
add tag to Spot VM
Create an Alert Rule
Go to Monitor – Alert page
Create an alert rule condition, if threshold for VM Aaailabiity Metric is less than 1 (means stopped), the alert will be triggered. The alert will check the condition every minute.
Next step is to create action group. It has to be in same subscription. Action group has to be in same subscription as your monitoring resources.
You even can set up SMS notification to notify you the server is stopped.
Notitication setting does not matter. SMS is not free anyway. One SMS is about one dime.