Distribuera Azure Spot Virtual Machines med hjälp av en Resource Manager mall
Gäller för: ✔️ Virtuella Linux-datorer
Med Azure Spot Virtual Machines kan du dra nytta av vår outnyttjade kapacitet med betydande kostnadsbesparingar. När Azure behöver tillbaka kapaciteten avlägsnar Azure-infrastrukturen Azure Spot Virtual Machines. Därför är Azure Spot Virtual Machines bra för arbetsbelastningar som kan hantera avbrott som batchbearbetningsjobb, utvecklings-/testmiljöer, stora beräkningsarbetsbelastningar med mera.
Priserna för Azure Spot Virtual Machines varierar beroende på region och SKU. Mer information finns i Prissättning för virtuella datorer för Linux och Windows.
Du har möjlighet att ange ett maxpris som du är villig att betala per timme för den virtuella datorn. Maxpriset för en virtuell Azure Spot-dator kan anges i amerikanska dollar (USD) med upp till 5 decimaler. Värdet skulle till exempel vara 0.98765 ett maxpris på 0,98765 USD per timme. Om du anger maxpriset till tas den virtuella -1 datorn inte bort baserat på priset. Priset för den virtuella datorn är det aktuella priset för Azure Spot Virtual Machines eller priset för en standard-VM, som någonsin är mindre, så länge det finns tillgänglig kapacitet och kvot. Mer information om hur du anger maxpriset finns i Azure Spot Virtual Machines – Priser.
Använda en mall
Använd eller senare för malldistributioner av virtuella Azure "apiVersion": "2019-03-01" Spot-datorer. Lägg till priority egenskaperna , och i i evictionPolicy billingProfile mallen:
"priority": "Spot",
"evictionPolicy": "Deallocate",
"billingProfile": {
"maxPrice": -1
}
Här är en exempelmall med de tillagda egenskaperna för en virtuell Azure Spot-dator. Ersätt resursnamnen med dina egna och <password> med ett lösenord för det lokala administratörskontot på den virtuella datorn.
{
"$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": "18.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')]"
}
}
}
Simulera en avlägsning
Du kan simulera en avlägsning av en virtuell Azure Spot-dator för att testa hur väl ditt program kommer att bli en plötslig avlägsning.
Ersätt följande med din information:
subscriptionIdresourceGroupNamevmName
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/simulateEviction?api-version=2020-06-01
Nästa steg
Du kan också skapa en virtuell Azure Spot-dator med Azure PowerShell eller Azure CLI.
Fråga aktuell prisinformation med hjälp av AZURE-API:et för detaljhandelspriser för information om priser för virtuella Azure-datorer med Spot. och meterName skuName innehåller båda Spot .
Om du stöter på ett fel kan du se Felkoder.