你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
使用 ARM 模板创建 Azure 计算机群(预览版)
重要
Azure 计算舰队目前以预览版提供。 需同意补充使用条款才可使用预览版。 在正式版 (GA) 推出之前,此功能的某些方面可能会有所更改。
本文逐步介绍如何使用 ARM 模板创建 Azure 计算机群。
Azure 资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 模板使用声明性语法。 你可以在不编写用于创建部署的编程命令序列的情况下,描述预期部署。
先决条件
- 如果没有 Azure 订阅,请在开始之前创建一个免费帐户。
- 在使用计算机群之前,请完成功能注册并配置基于角色的访问控制 (RBAC)。
功能注册
使用 PowerShell 或 Azure 门户将 Azure 计算机群资源提供程序注册到订阅。 注册可能需要多达 30 分钟才能成功显示“已注册”。
Register-AzResourceProvider -ProviderNamespace Microsoft.AzureFleet
基于角色的访问控制权限
分配适当的 RBAC 权限以使用 Azure 计算机群。
- 在“Azure 门户”中,导航到订阅。
- 选择要调整 RBAC 权限的订阅。
- 选择访问控制 (IAM)。
- 依次选择“添加”、“添加角色分配”。
- 搜索“虚拟机参与者”并将其突出显示。 选择下一步。
- 单击“+ 选择成员”。
- 搜索“Azure 机群资源提供程序”角色。
- 选择“Azure 机群资源提供程序”,然后选择“审核 + 分配”。
- 对“网络参与者”角色和“托管标识操作员”角色重复上述步骤。
如果在部署计算机群时使用存储在计算库中的映像,请对“计算库共享管理员”角色重复上述步骤。
有关分配角色的信息,请参阅使用 Azure 门户分配 Azure 角色。
ARM 模板
Azure 资源管理器模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。 模板使用声明性语法。 你可以在不编写用于创建部署的编程命令序列的情况下,描述预期部署。
ARM 模板允许部署相关资源的组。 在单个模板中,可以创建虚拟机规模集、安装应用程序,以及配置自动缩放规则。 使用变量和参数时,可以重复使用此模板来更新现有规模集或创建额外的规模集。 可通过 Azure 门户、Azure CLI、Azure PowerShell 或持续集成/持续交付 (CI/CD) 管道部署模板。
查看模板
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"fleetName": {
"type": "string",
"metadata": {
"description": "String used as a base for naming resources. Must be 3-61 characters in length and globally unique across Azure. A hash is prepended to this string for some resources, and resource-specific information is appended."
}
},
"adminUsername": {
"type": "string",
"defaultValue": "testusername",
"metadata": {
"description": "Admin username on all VMs."
}
},
"adminPassword": {
"type": "string",
"metadata": {
"description": "Admin password on all VMs."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
}
},
"variables": {
"vnName": "[format('{0}-vnet', parameters('fleetName'))]",
"lbName": "[format('{0}-lb', parameters('fleetName'))]",
"imageReference": {
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2019-DataCenter-GS",
"version": "latest"
}
},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2022-07-01",
"name": "[variables('vnName')]",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"subnets": [
{
"name": "default",
"properties": {
"addressPrefix": "10.0.0.0/24"
}
}
]
}
},
{
"type": "Microsoft.Network/loadBalancers",
"apiVersion": "2022-07-01",
"name": "[variables('lbName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"frontendIPConfigurations": [
{
"name": "[variables('lbName')]",
"properties": {
"privateIPAddress": "10.0.0.4",
"privateIPAllocationMethod": "Dynamic",
"subnet": {
"id": "[reference(resourceId('Microsoft.Network/virtualNetworks', variables('vnName'))).subnets[0].id]"
}
}
}
],
"backendAddressPools": [
{
"name": "[variables('lbName')]"
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnName'))]"
]
},
{
"type": "Microsoft.AzureFleet/fleets",
"apiVersion": "2024-05-01-Preview",
"name": "[toLower(parameters('fleetName'))]",
"location": "[parameters('location')]",
"properties": {
"vmSizesProfile": [
{
"name": "Standard_F2s_v2"
},
{
"name": "Standard_DS1_v2"
},
{
"name": "Standard_DS2_v2"
}
],
"spotPriorityProfile": {
"capacity": 10,
"evictionPolicy": "Delete",
"allocationStrategy": "CapacityOptimized",
"maintain": false
},
"regularPriorityProfile": {
"capacity": 50,
"minCapacity": 30,
"allocationStrategy": "LowestPrice"
},
"computeProfile": {
"platformFaultDomainCount": 1,
"computeApiVersion": "2024-03-01",
"baseVirtualMachineProfile": {
"storageProfile": {
"osDisk": {
"osType": "Windows",
"createOption": "fromImage",
"caching": "ReadWrite",
"managedDisk": {
"storageAccountType": "Standard_LRS"
}
},
"imageReference": "[variables('imageReference')]"
},
"osProfile": {
"computerNamePrefix": "[parameters('fleetName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"networkProfile": {
"networkApiVersion": "2022-07-01",
"networkInterfaceConfigurations": [
{
"name": "[variables('vnName')]",
"properties": {
"primary": true,
"enableIPForwarding": true,
"enableAcceleratedNetworking": false,
"ipConfigurations": [
{
"name": "[variables('vnName')]",
"properties": {
"subnet": {
"id": "[reference(resourceId('Microsoft.Network/virtualNetworks', variables('vnName'))).subnets[0].id]"
},
"primary": true,
"applicationGatewayBackendAddressPools": [],
"loadBalancerBackendAddressPools": [
{
"id": "[format('{0}/backendAddressPools/{1}', resourceId('Microsoft.Network/loadBalancers', variables('lbName')), variables('lbName'))]"
}
]
}
}
]
}
}
]
}
}
}
},
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', variables('vnName'))]",
"[resourceId('Microsoft.Network/loadBalancers', variables('lbName'))]"
]
}
]
}
该模板中定义了以下资源:
清理资源
如果不再需要资源组、规模集和所有相关的资源,可以使用 az group delete 命令将其删除,如下所示。 --no-wait
参数会使光标返回提示符处,无需等待操作完成。 使用 --yes
参数将确认你希望删除资源,不会再通过其他提示进行询问。
az group delete --name myResourceGroup --yes --no-wait