Azure Spot Virtual Machines implementeren met behulp van een Resource Manager-sjabloon

Van toepassing op: ✔️ Linux-VM's

Met Behulp van Azure Spot Virtual Machines kunt u profiteren van onze ongebruikte capaciteit tegen aanzienlijke kostenbesparingen. Op elk moment dat Azure de capaciteit terug nodig heeft, worden spot-VM's door de Azure-infrastructuur verwijderd. Azure Spot-VM's zijn ideaal voor workloads die onderbrekingen kunnen verwerken, zoals batchverwerkingstaken, ontwikkel-/testomgevingen, 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 informatie.

U hebt de optie om een maximumprijs in te stellen die u per uur voor de VIRTUELE machine wilt betalen. De maximale prijs voor een Azure Spot-VM kan worden ingesteld in Amerikaanse dollars (USD), met maximaal vijf decimalen. De waarde 0.98765is bijvoorbeeld een maximale prijs van USD 0,98765 per uur. Als u de maximumprijs instelt op -1, is de verwijdering van vm's niet gebaseerd op de prijs en is de prijs de huidige prijs voor azure-spot-VM's of de prijs voor een standaard-VM, afhankelijk van wat minder is, zolang er capaciteit en quotum beschikbaar is. Zie Azure Spot-VM's - Prijzen voor meer informatie over het instellen van de maximumprijs.

Een sjabloon gebruiken

Gebruik of hoger voor implementaties"apiVersion": "2019-03-01" van Azure Spot VM-sjablonen. Voeg de priorityeigenschappen en billingProfileevictionPolicy toe aan in uw sjabloon:

"priority": "Spot",
"evictionPolicy": "Deallocate",
"billingProfile": {
    "maxPrice": -1
}

Hier volgt een voorbeeldsjabloon met toegevoegde eigenschappen voor een Azure Spot-VM. Vervang de resourcenamen door uw eigen 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": "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')]"
        }
    }
}

Een verwijdering simuleren

U kunt een verwijdering van een Azure Spot-VM simuleren om de reactie van uw toepassing op een plotselinge verwijdering te testen.

Vervang de onderstaande parameters door uw gegevens:

  • subscriptionId
  • resourceGroupName
  • vmName
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/simulateEviction?api-version=2020-06-01

Volgende stappen