Resource Manager 템플릿을 이용해 Azure Spot Virtual Machines 배포하기

적용 대상: ✔️ Linux VM

Azure Spot Virtual Machines를 사용하면 대폭 절감된 비용으로 사용되지 않은 용량을 활용할 수 있습니다. 언제든지 Azure에 용량이 다시 필요하면 Azure 인프라가 Azure 스폿 VM을 제거합니다. 스폿 VM은 일괄 처리 작업, 개발/테스트 환경, 대규모 컴퓨팅 작업 등과 같은 중단을 처리할 수 있는 작업에 매우 적합합니다.

Azure Spot Virtual Machines의 가격 책정은 지역과 SKU에 따라 다릅니다. 자세한 내용은 LinuxWindows에 대한 VM 가격 책정을 참조하세요.

VM에 대해 시간당 지불할 최고 가격을 설정하는 옵션이 있습니다. Azure 스폿 VM 한 대당 최고 가격을 미국 달러(USD)로 최대 소수 자릿수 5자리까지 설정할 수 있습니다. 예를 들어 0.98765 값은 시간당 $0.98765 USD의 최대 가격이 됩니다. 최고 가격을 -1로 설정하면 VM 제거는 가격을 기반으로 하지 않으며 사용 가능한 용량과 할당량이 있는 한 Azure 스폿 VM의 현재 가격 또는 표준 VM의 가격이 됩니다. 최고 가격을 설정하는 방법에 대한 자세한 내용은 Azure 스폿 VM - 가격 책정을 참조하세요.

템플릿 사용

Azure 스폿 VM 템플릿 배포에는 "apiVersion": "2019-03-01" 이상을 사용합니다. 템플릿에 priority, evictionPolicy, billingProfile 속성을 추가합니다.

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

다음은 Azure 스폿 VM의 속성이 추가된 샘플 템플릿입니다. 리소스 이름을 내 이름으로 바꾸고 <password>를 해당 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')]"
        }
    }
}

제거 시뮬레이션

Azure 스폿 VM 제거를 시뮬레이션하여 애플리케이션이 갑작스러운 제거에 얼마나 잘 대응하는지 테스트할 수 있습니다.

아래 매개 변수를 정보로 바꿉니다.

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

다음 단계

  • Azure PowerShell 또는 Azure CLI를 사용해 Azure 스폿 VM을 만들 수도 있습니다.
  • Azure 스폿 VM의 현재 가격 책정에 대한 자세한 내용은 Azure 소매 가격 API를 참조하세요. meterNameskuName은 모두 Spot을 포함합니다.
  • 오류에 대한 자세한 내용은 오류 코드를 참조하세요.