Azure负载平衡器-使用ARM模板将现有VM添加到Azure负载平衡器

时间:2020-07-14 10:39:04

标签: azure azure-devops arm-template azure-load-balancer azure-vm

我有两个VMS backendvm0和backendvm1,我试图从负载均衡器ARM模板部署中将这些Vms添加到Azure负载均衡器的后端池中。我正在使用如下的参数对象。它没有给出任何错误,正在创建名称为tlba001backendpool_test的负载均衡器,但未显示任何附加的虚拟机。

 "backendAddressPools": {
  "value": [
    {
      "name": "tlba001backendpool_test",
      "id": "",
      "properties": {
        "loadBalancerBackendAddresses": [
          {
            "name": "backendvm0",
            "properties": {
              "ipAddress": "10.0.2.5"
            }

          },
          {
            "name": "backendvm1",
            "properties": {
              "ipAddress": "10.0.2.4"
            }
          }
        ] 

      }
    }
  ]
},

enter image description here

1 个答案:

答案 0 :(得分:2)

由于这是由nic属性(而不是负载均衡器)控制的,因此您需要修改NIC属性并将NIC分配给负载均衡器。

{
    "apiVersion": "2015-05-01-preview",
    "type": "Microsoft.Network/networkInterfaces",
    "name": "[concat(parameters('nicNamePrefix'), copyindex())]",
    "location": "[resourceGroup().location]",
    "copy": {
        "name": "nicLoop",
        "count": "[variables('numberOfInstances')]"
    },
    "dependsOn": [
        "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]",
        "[concat('Microsoft.Network/loadBalancers/', parameters('lbName'))]"
    ],
    "properties": {
        "ipConfigurations": [
            {
                "name": "ipconfig1",
                "properties": {
                    "privateIPAllocationMethod": "Dynamic",
                    "subnet": {
                        "id": "[variables('subnetRef')]"
                    },
                    "loadBalancerBackendAddressPools": [
                        {
                            "id": "[concat(variables('lbID'), '/backendAddressPools/BackendPool1')]"
                        }
                    ]
                }
            }
        ]
    }
}

https://github.com/Azure/azure-quickstart-templates/blob/master/201-2-vms-loadbalancer-lbrules/azuredeploy.json