Menyebarkan Azure Spot Virtual Machines menggunakan templat Manajer Sumber Daya

Berlaku untuk: ✔️ mesin virtual Linux

Menggunakan Azure Spot Virtual Machines memungkinkan Anda untuk memanfaatkan kapasitas kami yang tidak digunakan dengan menghemat biaya secara signifikan. Kapan saja ketika Azure membutuhkan kapasitas kembali, infrastruktur Azure mengeluarkan Azure Spot VM. Azure Spot VM sangat bagus untuk beban kerja yang dapat menangani gangguan seperti pekerjaan pemrosesan batch, lingkungan dev/test, beban kerja komputasi besar, dan banyak lagi.

Harga untuk Azure Spot Virtual Machines bervariasi berdasarkan wilayah dan SKU. Untuk informasi selengkapnya, lihat harga VM untuk Linux dan Windows.

Anda memiliki opsi untuk menetapkan harga maksimum yang bersedia Anda bayar, per jam, untuk VM. Harga maksimum untuk Azure Spot VM dapat diatur dalam dolar AS (USD), menggunakan hingga lima tempat desimal. Misalnya, nilai 0.98765 akan menjadi harga maks $ 0,98765 USD per jam. Jika Anda menetapkan harga maksimum menjadi -1, pengeluaran VM tidak didasarkan pada harga dan harganya akan menjadi harga saat ini untuk Azure Spot VM atau harga untuk VM standar, mana yang lebih sedikit, selama ada kapasitas dan kuota yang tersedia. Untuk informasi selengkapnya tentang mengatur harga maksimum, lihat Azure Spot VM - Harga.

Menggunakan templat

Untuk penyebaran templat Azure Spot VM, gunakan"apiVersion": "2019-03-01" atau yang lebih baru. Tambahkan properti priority, evictionPolicy, dan billingProfile ke dalam templat Anda:

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

Berikut adalah contoh templat dengan properti tambahan untuk Azure Spot VM. Ganti nama sumber daya dengan nama pilihan Anda dan ganti <password> dengan kata sandi untuk akun administrator lokal pada 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')]"
        }
    }
}

Menyimulasikan pengusiran

Anda dapat mensimulasikan pengeluaran Azure Spot VM, untuk menguji respons aplikasi Anda terhadap pengeluaran mendadak.

Ganti parameter di bawah ini dengan informasi Anda:

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

Langkah berikutnya