|
| 1 | +--- |
| 2 | +title: Use Azure Spot Virtual Machines |
| 3 | +description: Learn how to use Azure Spot Virtual Machines to save on costs. |
| 4 | +author: am4234m |
| 5 | +ms.author: aparnamishra |
| 6 | +ms.service: azure-virtual-machines |
| 7 | +ms.subservice: azure-spot-vm |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 08/05/2024 |
| 10 | +ms.reviewer: ju-shim |
| 11 | +--- |
| 12 | + |
| 13 | + |
| 14 | +# Use Azure Spot Virtual Machines |
| 15 | + |
| 16 | +**Applies to:** :heavy_check_mark: Linux VMs :heavy_check_mark: Windows VMs :heavy_check_mark: Flexible scale sets :heavy_check_mark: Uniform scale sets |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +## Eviction policy |
| 21 | + |
| 22 | +Spot VMs can be stopped if Azure needs capacity for other pay-as-you-go workloads or when the price of the spot instance exceeds the maximum price that you have set. When creating an Azure Spot Virtual Machine, you can set the eviction policy to *Deallocate* (default) or *Delete*. |
| 23 | + |
| 24 | +The *Deallocate* policy moves your VM to the stopped-deallocated state, allowing you to redeploy it later. However, there's no guarantee that the allocation will succeed. The deallocated VMs will count against your quota and you'll be charged storage costs for the underlying disks. |
| 25 | + |
| 26 | +If you would like your VM to be deleted when it's evicted, you can set the eviction policy to *delete*. The evicted VMs are deleted together with their underlying disks, so you'll not continue to be charged for the storage. |
| 27 | + |
| 28 | +You can opt in to receive in-VM notifications through [Azure Scheduled Events](./linux/scheduled-events.md). These are delivered on a best effort basis up to 30 seconds prior to the eviction. |
| 29 | + |
| 30 | + |
| 31 | +| Option | Outcome | |
| 32 | +|--------|---------| |
| 33 | +| Max price is set to >= the current price. | VM is deployed if capacity and quota are available. | |
| 34 | +| Max price is set to < the current price. | The VM isn't deployed. You'll get an error message that the max price needs to be >= current price. | |
| 35 | +| Restarting a stopped/deallocated VM if the max price is >= the current price | If there's capacity and quota, then the VM is deployed. | |
| 36 | +| Restarting a stopped/deallocated VM if the max price is < the current price | You'll get an error message that the max price needs to be >= current price. | |
| 37 | +| Price for the VM has gone up and is now > the max price. | The VM gets evicted. Azure will attempt scheduled event delivery up to 30 seconds before actual eviction. | |
| 38 | +| After eviction, the price for the VM goes back to being < the max price. | The VM won't be automatically restarted. You can restart the VM yourself, and it will be charged at the current price. | |
| 39 | +| If the max price is set to `-1` | The VM won't be evicted for pricing reasons. The max price will be the current price, up to the price for standard VMs. You'll never be charged above the standard price.| |
| 40 | +| Changing the max price | You need to deallocate the VM to change the max price. Deallocate the VM, set a new max price, then update the VM. | |
| 41 | + |
| 42 | +> [!TIP] |
| 43 | +> Check out our [Azure Virtual Machine Spot Eviction](/azure/architecture/guide/spot/spot-eviction) guide to learn how to create a reliable interruptible workload in Azure. |
| 44 | +
|
| 45 | +## Limitations |
| 46 | + |
| 47 | +The following VM sizes aren't supported for Azure Spot Virtual Machines: |
| 48 | + - B-series |
| 49 | + - Promo versions of any size (like Dv2, NV, NC, H promo sizes) |
| 50 | + |
| 51 | +Azure Spot Virtual Machines can be deployed to any region, except Microsoft Azure operated by 21Vianet. |
| 52 | + |
| 53 | +<a name="channel"></a> |
| 54 | + |
| 55 | +The following [offer types](https://azure.microsoft.com/support/legal/offer-details/) are currently supported: |
| 56 | + |
| 57 | +- Enterprise Agreement |
| 58 | +- Pay-as-you-go offer code (003P) |
| 59 | +- Sponsored (0036P and 0136P) - not available in Fairfax |
| 60 | +- For Cloud Service Provider (CSP), see the [Partner Center](/partner-center/azure-plan-get-started) or contact your partner directly. |
| 61 | + |
| 62 | + |
| 63 | +## Pricing |
| 64 | + |
| 65 | +Pricing for Azure Spot Virtual Machines is variable, based on region and SKU. For more information, see VM pricing for [Linux](https://azure.microsoft.com/pricing/details/virtual-machines/linux/) and [Windows](https://azure.microsoft.com/pricing/details/virtual-machines/windows/). |
| 66 | + |
| 67 | +You can also query pricing information using the [Azure retail prices API](/rest/api/cost-management/retail-prices/azure-retail-prices) to query for information about Spot pricing. The `meterName` and `skuName` will both contain `Spot`. |
| 68 | + |
| 69 | +With variable pricing, you have option to set a max price, in US dollars (USD), using up to five decimal places. For example, the value `0.98765`would be a max price of $0.98765 USD per hour. If you set the max price to be `-1`, the VM won't be evicted based on price. The price for the VM will be the current price for spot or the price for a standard VM, which ever is less, as long as there's capacity and quota available. |
| 70 | + |
| 71 | +## Pricing and eviction history |
| 72 | + |
| 73 | +### Portal |
| 74 | + |
| 75 | +You can see historical pricing and eviction rates per size in a region in the portal while you are creating the VM. After selecting the checkbox to **Run with Azure Spot discount**, a link will appear under the size selection of the VM titled **View pricing history and compare prices in nearby regions**. By selecting that link you will be able to see a table or graph of spot pricing for the specified VM size. The pricing and eviction rates in the following images are only examples. |
| 76 | + |
| 77 | +> [!TIP] |
| 78 | +> Eviction rates are quoted _per hour_. For example, an eviction rate of 10% means a VM has a 10% chance of being evicted within the next hour, based on historical eviction data of the last 7 days. |
1 | 79 |
|
0 commit comments