Proposed Pull Request Change

title description author ms.service ms.subservice ms.custom ms.topic ms.date ms.author ms.reviewer
Use a template to deploy Azure Spot Virtual Machines Learn how to use a template to deploy Azure Spot Virtual Machines to save costs. iamwilliew azure-virtual-machines azure-spot-vm linux-related-content how-to 05/31/2023 wwilliams wwilliams
📄 Document Links
GitHub View on GitHub Microsoft Learn View on Microsoft Learn
⚠ Content Truncation Detected
The generated rewrite appears to be incomplete.
Original lines: -
Output lines: -
Ratio: -
Raw New Markdown
Generating updated version of doc...
Rendered New Markdown
Generating updated version of doc...
+0 -0
+0 -0
--- title: Use a template to deploy Azure Spot Virtual Machines description: Learn how to use a template to deploy Azure Spot Virtual Machines to save costs. author: iamwilliew ms.service: azure-virtual-machines ms.subservice: azure-spot-vm ms.custom: linux-related-content ms.topic: how-to ms.date: 05/31/2023 ms.author: wwilliams ms.reviewer: wwilliams # Customer intent: "As a cloud architect, I want to deploy Azure Spot Virtual Machines using a template, so that I can optimize costs while efficiently managing workloads that can tolerate interruptions." --- # Deploy Azure Spot Virtual Machines using a Resource Manager template **Applies to:** :heavy_check_mark: Linux VMs Using [Azure Spot Virtual Machines](../spot-vms.md) allows you to take advantage of our unused capacity at a significant cost savings. At any point in time when Azure needs the capacity back, the Azure infrastructure evicts Azure Spot VMs. Azure Spot VMs are great for workloads that can handle interruptions like batch processing jobs, dev/test environments, large compute workloads, and more. 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/). You have option to set a max price you're willing to pay, per hour, for the VM. The max price for an Azure Spot VM can be set 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 VMs eviction is not based on price and it's price will be the current price for Azure Spot VMs or the price for a standard VM, whichever is less, as long as there's capacity and quota available. For more information about setting the max price, see [Azure Spot VMs - Pricing](../spot-vms.md#pricing). ## Use a template For Azure Spot VM template deployments, use`"apiVersion": "2019-03-01"` or later. Add the `priority`, `evictionPolicy` and `billingProfile` properties to in your template: ```json "priority": "Spot", "evictionPolicy": "Deallocate", "billingProfile": { "maxPrice": -1 } ``` Here's a sample template with added properties for an Azure Spot VM. Replace the resource names with your own and `<password>` with a password for the local administrator account on the VM. ```json { "$schema": "http://schema.management.azure.com/schemas/2019-03-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { }, "variables": { "vnetId": "/subscriptions/ec9fcd04-e188-48b9-abfc-abcd515f1836/resourceGroups/spotVM/providers/Microsoft.Network/virtualNetworks/spotVM", "subnetName": "default", "networkInterfaceName": "spotVMNIC", "publicIpAddressName": "spotVM-ip", "publicIpAddressType": "Dynamic", "publicIpAddressSku": "Basic", "virtualMachineName": "spotVM", "osDiskType": "Premium_LRS", "virtualMachineSize": "Standard_D2s_v3", "adminUsername": "azureuser", "adminPassword": "<password>", "diagnosticsStorageAccountName": "diagstoragespot2019", "diagnosticsStorageAccountId": "Microsoft.Storage/storageAccounts/diagstoragespot2019", "diagnosticsStorageAccountType": "Standard_LRS", "diagnosticsStorageAccountKind": "Storage", "subnetRef": "[concat(variables('vnetId'), '/subnets/', variables('subnetName'))]" }, "resources": [ { "name": "spotVM", "type": "Microsoft.Network/networkInterfaces", "apiVersion": "2019-03-01", "location": "eastus", "dependsOn": [ "[concat('Microsoft.Network/publicIpAddresses/', variables('publicIpAddressName'))]" ], "properties": { "ipConfigurations": [ { "name": "ipconfig1", "properties": { "subnet": { "id": "[variables('subnetRef')]" }, "privateIPAllocationMethod": "Dynamic", "publicIpAddress": { "id": "[resourceId(resourceGroup().name, 'Microsoft.Network/publicIpAddresses', variables('publicIpAddressName'))]" } } } ] } }, { "name": "[variables('publicIpAddressName')]", "type": "Microsoft.Network/publicIpAddresses", "apiVersion": "2019-02-01", "location": "eastus", "properties": { "publicIpAllocationMethod": "[variables('publicIpAddressType')]" }, "sku": { "name": "[variables('publicIpAddressSku')]" } }, { "name": "[variables('virtualMachineName')]", "type": "Microsoft.Compute/virtualMachines", "apiVersion": "2019-03-01", "location": "eastus", "dependsOn": [ "[concat('Microsoft.Network/networkInterfaces/', variables('networkInterfaceName'))]", "[concat('Microsoft.Storage/storageAccounts/', variables('diagnosticsStorageAccountName'))]" ], "properties": { "hardwareProfile": { "vmSize": "[variables('virtualMachineSize')]" }, "storageProfile": { "osDisk": { "createOption": "fromImage", "managedDisk": { "storageAccountType": "[variables('osDiskType')]" } }, "imageReference": { "publisher": "Canonical", "offer": "UbuntuServer", "sku": "22.04-LTS", "version": "latest" } }, "networkProfile": { "networkInterfaces": [ { "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkInterfaceName'))]" } ] }, "osProfile": { "computerName": "[variables('virtualMachineName')]", "adminUsername": "[variables('adminUsername')]", "adminPassword": "[variables('adminPassword')]" }, "diagnosticsProfile": { "bootDiagnostics": { "enabled": true, "storageUri": "[concat('https://', variables('diagnosticsStorageAccountName'), '.blob.core.windows.net/')]" } }, "priority": "Spot", "evictionPolicy": "Deallocate", "billingProfile": { "maxPrice": -1 } } }, { "name": "[variables('diagnosticsStorageAccountName')]", "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2019-04-01", "location": "eastus", "properties": {}, "kind": "[variables('diagnosticsStorageAccountKind')]", "sku": { "name": "[variables('diagnosticsStorageAccountType')]" } } ], "outputs": { "adminUsername": { "type": "string", "value": "[variables('adminUsername')]" } } } ``` ## Simulate an eviction You can [simulate an eviction](/rest/api/compute/virtualmachines/simulateeviction) of an Azure Spot VM, to test your application response to a sudden eviction. Replace the below parameters with your information: - `subscriptionId` - `resourceGroupName` - `vmName` ```http POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/simulateEviction?api-version=2020-06-01 ``` ## Next steps * You can also create an Azure Spot VM using [Azure PowerShell](../windows/spot-powershell.md) or the [Azure CLI](spot-cli.md). * For more information about Azure Spot VM current pricing, see [Azure retail prices API](/rest/api/cost-management/retail-prices/azure-retail-prices). Both `meterName` and `skuName` contains `Spot`. * To learn more about an error, see [Error codes](../error-codes-spot.md).
Success! Branch created successfully. Create Pull Request on GitHub
Error: