How to Use Azure Spot to Reduce Azure Virtualization Costs

Save to My DOJO

How to Use Azure Spot to Reduce Azure Virtualization Costs

One of the key benefits of cloud computing is the resource optimization achieved through hardware abstraction. This article explains how Azure Spot can provide a scalable virtualization management solution saving you from using unnecessary VMs.

What is Azure Spot?

When a workload becomes virtualized, it is no longer bound to any specific server and can be placed on any host with available and compatible resources. This allows organizations to consolidate their hardware and reduce their expenses by optimizing the placement of these virtual machines (VMs) so that they are most efficiently using the underlying hardware. For example, a server running several VMs with only 50% resource utilization could likely host a few more VMs or other services with its remaining capacity. If additional capacity is needed, the lowest priority VMs could be evicted from the host and replaced with more important workloads. Today this is a common practice today in private clouds where the admin has access to the hosts, however, it has been challenging to do this in a public cloud where access to the physical hardware is not provided to users.

Microsoft Azure recently announced the general availability of Azure Spot Virtual Machines, which enables low priority VMs to be evicted and shut down when the host’s resources are needed. This provides equivalent features as Amazon Web Services (AWS) EC2 Spot Instances and Google Cloud Platform (GCP) Preemptible VMs. Similar functionality was provided by Microsoft Azure in the past through Virtual Machine Scale Set (VMSS) using low priority VMs. Spot VMs are replacing low priority VMs and any existing VMSS low priority VMs should be migrated to Spot VMs.

Azure Spot VMs should only be used in specific scenarios, however, they are very cheap to run. Essentially these Spot VMs run on “unsold” cloud capacity, so they are significantly discounted (up to 90%) and can be assigned a capped maximum price. We will now discuss an overview of the technology and key workloads you should move to Azure Spot VMs to minimize your operating costs. If you are a managed service provider (MSP), then these are recommendations that you can pass along to your tenants.

Azure Spot VM Workloads

The most important characteristic of a Spot VM is that it can be tuned off and evicted at any time by another VM when its resources are needed or if the cost becomes too high. This is a hard shutdown, which is equivalent to switching off the power, so you will only have a limited window to save any data or the state of the VM. This means that VMs which are being accessed by customers or contain data that you want to retain are generally not suitable. Here are the most common workloads or tasks deployed with Windows or Linux Spot VMs.

  • Stateless: A service which just serves a single purpose, and is not required to store any state, such as a web server with static content.
  • Interruptible: A service that can be stopped at any time, such as with brute force testing application.
  • Short: A service that can run quickly, such as scalable application.
  • Batch: A service that collects then batches a series of tasks to maximize hardware utilization for a short burst, such as a scale computation.
  • Untimed: A service that contains many tasks which can take a long time to complete, but has no specific deadline for completion.
  • Dev/Test: A service that is commonly used for continuous integration or delivery for a development team.

 

A Spot VM functions just like a pay-as-you-go VM, with the exception that it can be evicted. If you decide to use Spot VMs for different types of workloads, this is fully supported, but you accept the risks that come with it. 30 seconds before an eviction happens, a notification is provided which can be detected by the system so it can try to save data or close connections before the Spot VM is stopped. You could try to create VM checkpoints at regular intervals, which will allow you to restore a Spot VM to its last saved state, however, you would pay for the storage capacity for the virtual hard disk and its checkpoint(s), even if the VM is offline.

Deploying an Azure Spot VM

It is simple to configure a Spot VM in any Azure region. When creating a new VM using the Azure Portal, Azure PowerShell, Azure CLI or an Azure Resource Manager (ARM) Template, you can specify that the VM should use an Azure Spot instance. Using the Portal as the example, you will find that the Basics > Instance details tab lets you enable the Spot VM functionality (it is disabled by default). If you select a Spot VM, you can define the eviction policy and price controls, which are covered in a later section of this article. The following screenshot shows these settings. You can then create and manage the VM like any other Windows or Linux VM running in Azure.

 

Deploying an Azure Spot VM

Figure 1 – Creating an Azure Spot VM from the Azure Portal

Evicting an Azure Spot VM

While an Azure Spot VM gives you a great deal on pricing, the VM can be shut down at any time and preempted by another VM from a customer willing to pay more, or if the cost exceeds the maximum price you have agreed to pay. You will receive a 30-second warning through the event channel that an eviction is about to happen, which may give you a chance to save some data or even take a snapshot, but this should not be used as a reliable way to retain important data. To see these notifications you can subscribe to Scheduled Events, which can trigger any type of task or command, such as attempting to save the data.

When you create the Spot VM, you must select either the Deallocate (default) or Delete eviction policy. The Delete option will permanently delete the VMs and its disks and there will be no additional costs. A Deallocate policy means that the VM has been evicted and placed into a Stopped-Deallocated State, and its VHD file is saved. A deallocated VM can be redeployed later if capacity frees up – although there is not a guarantee that this will ever happen. You also have to pay for the storage used by this file, so be careful if you are running a lot of Spot VMs with this setting. If you want to redeploy that VM, you will have to restart it from the Azure Portal or using Azure PowerShell or CLI. Even if the price goes down in the future, it will not automatically restart.

Virtual Machine Scale Sets (VMSS) and Azure Spot VMs

Azure Spot VMs are fully integrated and compatible with VM Scale Sets (VMSS). A VMSS lets you run a virtualized application behind a load-balancer that can dynamically scale up or down based on user load. By using Spot VMs with a VMSS, you can scale up only when the costs are below the maximum price which you have assigned. To create a Spot VMs set, you can set the priority flag to Spot via the portal, PowerShell, CLI, or in the Azure Resource Manager (ARM) template. At this time, an existing scale set cannot be converted into a Spot scale set, this configuration must be enabled when the scale set is created. To ensure that the set does not grow too large, a Spot VM quota can be applied to the scale set. Automatically scaling the set using the autoscale rules is fully supported, however, any deallocated Spot VMs will count against the quota, even if they are not running. For this reason, it is recommended to use the Delete eviction option for the Spot VMs within a VMSS.

Pricing for Azure Spot VMs

When you create a Spot VM, you will see the current price for the region, image, and VM size which you have selected. The price is always displayed in US Dollars for consistency and transparency, even if you are using a different default currency for billing. The discounted price can range significantly, up to 90% cheaper than the base price. Keep in mind that if you are flexible on the type, size, or location of the VM, that you can browse different options to see the cheapest price.

The current price can increase as more hardware is requested by other users, so you can also set a max price that you are willing to pay. So long as the current price is below the capped price, the VM will stay running. However, if the price becomes more expensive than your max price, the VM will be evicted according to the policy you have specified. If you want to change the max price, you have to first deallocate the VM, update the price, then restart the VM. If you do not care what the max price is, so long as it is cheaper than the standard price, then you can set the max price to -1. In this scenario, you will pay either the discounted price or the standard price, whichever is cheaper.

Quotas for Azure Spot VM

Microsoft Azure has a concept called quotas which allows you to assign a maximum number of VM resources (vCPUs) to a particular user or group. In order to simplify management, Spot VMs have their own quota category which is separate from regular VMs. This allows admins or managed service providers (MSPs) to ensure that only a maximum number of Spot VMs are running, so that they do not accidentally over-deploy VMs which exceed their need or budget. This single quota is used for Spot VMs and Spot VMSS instances for all VMs in an Azure region. The following screenshot shows the Quota Details page for Spot VMs.


Assigning a Quota to Spot VMs

Figure 2 – Assigning a Quota to Spot VMs

Licensing for Azure Spot VMs

For the most part, Azure Spot VMs are the same as standard VMs. All VMs are supported as Spot VMs, excluding the B-Series and promo versions (Dv2, NV, NC, H). Spot VMs are also available in all regions, except China. Spot VMs are also not available with free trials nor as a benefit. Cloud Service Providers (CSPs) and managed service providers (MSPs) may offer Spot VMs as a service to their tenants.

Conclusion

Spot VMs will become a popular feature in Azure for any type of recommended workloads. This is another great example of how Microsoft is providing its customers with more deployment options and reducing costs while maximizing their hardware utilization. Are there any other types of workloads you think would work well with Spot VMs? Let us know by posting in the comments section below.

Threat Monitor
Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

Leave a comment or ask a question

Your email address will not be published. Required fields are marked *

Your email address will not be published. Required fields are marked *

Notify me of follow-up replies via email

Yes, I would like to receive new blog posts by email

What is the color of grass?

Please note: If you’re not already a member on the Dojo Forums you will create a new account and receive an activation email.