Azure Spot Virtual Machines implementeren met behulp van een Resource Manager sjabloon
Van toepassing op: ✔️ Linux-VM's
Door Azure Spot Virtual Machines kunt u profiteren van onze ongebruikte capaciteit tegen aanzienlijke kostenbesparingen. Op elk moment waarop Azure de capaciteit terug nodig heeft, zal de Azure-infrastructuur Azure Spot-Virtual Machines. Daarom zijn Azure Spot Virtual Machines geweldig voor workloads die onderbrekingen kunnen afhandelen, zoals batchverwerkingstaken, dev/test-omgevingen, grote rekenworkloads en meer.
Prijzen voor Azure Spot Virtual Machines zijn variabel, op basis van regio en SKU. Zie VM-prijzen voor Linux en Windows voor meer Windows.
U hebt de mogelijkheid om een maximumprijs in te stellen die u per uur voor de VM wilt betalen. De maximumprijs voor een virtuele Azure Spot-machine kan worden ingesteld in Amerikaanse dollars (USD), met maximaal 5 decimalen. De waarde zou bijvoorbeeld 0.98765 een maximale prijs van $ 0,98765 USD per uur zijn. Als u de maximumprijs in stelt op , wordt de VM niet op basis van -1 de prijs onbetaald. De prijs voor de VM is de huidige prijs voor Azure Spot Virtual Machines of de prijs voor een standaard-VM, die ooit lager is, zolang er capaciteit en quotum beschikbaar zijn. Zie Azure Spot Virtual Machines - Pricing (Prijzen)voor meer informatie over het instellen van de maximumprijs.
Een sjabloon gebruiken
Gebruik of hoger voor sjabloonimplementaties voor virtuele "apiVersion": "2019-03-01" Spot-machines in Azure. Voeg de priority eigenschappen , en toe aan in uw evictionPolicy billingProfile sjabloon:
"priority": "Spot",
"evictionPolicy": "Deallocate",
"billingProfile": {
"maxPrice": -1
}
Hier is een voorbeeldsjabloon met de toegevoegde eigenschappen voor een virtuele Spot-machine van Azure. Vervang de resourcenamen door uw eigen namen en <password> door een wachtwoord voor het lokale beheerdersaccount op de VM.
{
"$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')]"
}
}
}
Een verwijdering simuleren
U kunt een uitzetting van een virtuele Azure Spot-machine simuleren om te testen hoe goed uw toepassing wordt uitgesteld tot een plotselinge uitzetting.
Vervang het volgende door uw gegevens:
subscriptionIdresourceGroupNamevmName
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/simulateEviction?api-version=2020-06-01
Volgende stappen
U kunt ook een virtuele Azure Spot-machine maken met Azure PowerShell of de Azure CLI.
Vraag de huidige prijsinformatie op met behulp van de API voor azure-retailprijzen voor informatie over prijzen voor Spot Virtual Machine voor Azure. De meterName en bevatten beide skuName Spot .
Zie Foutcodes als er een fout is opgetreden.