如何更新/删除虚拟机规模集使用的 Azure 负载均衡器How to update/delete Azure Load Balancer used by Virtual Machine Scale Sets

如何设置 Azure 负载均衡器以横向扩展虚拟机规模集How to set up Azure Load Balancer for scaling out Virtual Machine Scale Sets

  • 确保负载均衡器已设置入站 NAT 池,并且虚拟机规模集已放在负载均衡器的后端池中。Make sure that the Load Balancer has inbound NAT pool set up and that the Virtual Machine Scale Set is put in the backend pool of the Load Balancer. 新的虚拟机实例被添加到虚拟机规模集时,Azure 负载均衡器将在入站 NAT 池中自动创建新的入站 NAT 规则。Azure Load Balancer will automatically create new inbound NAT rules in the inbound NAT pool when new Virtual Machine instances are added to the Virtual Machine Scale Set.
  • 若要检查入站 NAT 池是否设置正确,To check whether inbound NAT pool is properly set up,
  1. 通过 https://portal.azure.cn 登录到 Azure 门户。Sign in to the Azure portal at https://portal.azure.cn.

  2. 在左侧菜单中选择“所有资源”,然后在资源列表中选择“MyLoadBalancer”。Select All resources on the left menu, and then select MyLoadBalancer from the resource list.

  3. 在“设置”下,选择“入站 NAT 规则” 。Under Settings, select Inbound NAT Rules. 如果在右侧窗格中看到为虚拟机规模集中每个实例创建的规则的列表,那么恭喜你,你已经完成设置,可以随时进行扩展。If you see on the right pane, a list of rules created for each individual instance in the Virtual Machine Scale Set, the congrats you are all set to go for scaling up at any time.

如何添加入站 NAT 规则?How to add inbound NAT rules?

  • 无法添加单独的入站 NAT 规则。Individual inbound NAT rule cannot be added. 但是,可以为虚拟机规模集中的所有实例添加一组具有定义的前端端口范围和后端端口的入站 NAT 规则。However, you can add a set of inbound NAT rules with defined frontend port range and backend port for all instances in the Virtual Machine Scale Set.
  • 若要为虚拟机规模集添加一组完整的入站 NAT 规则,需要首先在负载均衡器中创建入站 NAT 池,然后从虚拟机规模集的网络配置文件引用入站 NAT 池。In order to add a whole set of inbound NAT rules for the Virtual Machine Scale Sets, you need to first create an inbound NAT pool in the Load Balancer, and then reference the inbound NAT pool from the network profile of Virtual Machine Scale Set. 下面显示了一个使用 CLI 的完整示例。A full example using CLI is shown below.
  • 新的入站 NAT 池不应具有与现有入站 NAT 池重叠的前端端口范围。The new inbound NAT pool should not have overlapping frontend port range with existing inbound NAT pools. 若要查看已设置的现有入站 NAT 池,可以使用此 CLI 命令To view existing inbound NAT pools set up, you can use this CLI command
az network lb inbound-nat-pool create 
        -g MyResourceGroup 
        --lb-name MyLb
        -n MyNatPool 
        --protocol Tcp 
        --frontend-port-range-start 80 
        --frontend-port-range-end 89 
        --backend-port 80 
        --frontend-ip-name MyFrontendIp
az vmss update 
        -g MyResourceGroup 
        -n myVMSS 
        --add virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].loadBalancerInboundNatPools "{'id':'/subscriptions/mySubscriptionId/resourceGroups/MyResourceGroup/providers/Microsoft.Network/loadBalancers/MyLb/inboundNatPools/MyNatPool'}"
        
az vmss update-instances
        -–instance-ids *
        --resource-group MyResourceGroup
        --name MyVMSS

如何更新入站 NAT 规则?How to update inbound NAT rules?

  • 无法更新单独的入站 NAT 规则。Individual inbound NAT rule cannot be updated. 但是,可以为虚拟机规模集中的所有实例更新一组具有定义的前端端口范围和后端端口的入站 NAT 规则。However, you can update a set of inbound NAT rules with defined frontend port range and backend port for all instances in the Virtual Machine Scale Set.
  • 若要更新虚拟机规模集的一组完整的入站 NAT 规则,需要更新负载均衡器中的入站 NAT 池。In order to update a whole set of inbound NAT rules for the Virtual Machine Scale Sets, you need to update the inbound NAT pool in the Load Balancer.
az network lb inbound-nat-pool update 
        -g MyResourceGroup 
        --lb-name MyLb 
        -n MyNatPool
        --protocol Tcp 
        --backend-port 8080

如何删除入站 NAT 规则?How to delete inbound NAT rules?

  • 无法删除单独的入站 NAT 规则。Individual inbound NAT rule cannot be deleted. 但是,可以删除整组入站 NAT 规则。However, you can delete the entire set of inbound NAT rules.
  • 若要删除规模集使用的一组完整的入站 NAT 规则,需要先从规模集中删除 NAT 池。In order to delete the whole set of inbound NAT rules used by the Scale Set, you need to first remove the NAT pool from the scale set. 下面显示了一个使用 CLI 的完整示例:A full example using CLI is shown below:
  az vmss update
     --resource-group MyResourceGroup
     --name MyVMSS
   az vmss update-instances 
     --instance-ids "*" 
     --resource-group MyResourceGroup
     --name MyVMSS
  az network lb inbound-nat-pool delete
     --resource-group MyResourceGroup
     -–lb-name MyLoadBalancer
     --name MyNatPool

如何添加多个 IP 配置:How to add multiple IP Configurations:

  1. 在左侧菜单中选择“所有资源”,然后在资源列表中选择“MyLoadBalancer”。Select All resources on the left menu, and then select MyLoadBalancer from the resource list.

  2. 在“设置”下,依次选择“前端 IP 配置”、“添加” 。Under Settings, select Frontend IP Configurations, and then select Add.

  3. 在“添加前端 IP 地址”页上,键入值并选择“确定” On the Add frontend IP address page, type in the values and select OK

  4. 如果需要新的负载均衡规则,请按照此教程中的步骤 5步骤 6 进行操作Follow Step 5 and Step 6 in this tutorial if new load balancing rules are needed

  5. 如果需要,使用新创建的前端 IP 配置创建一组新的入站 NAT 规则。Create new set of inbound NAT rules using the newly created frontend IP Configurations if needed. 可以在 [上一部分] 中找到相关示例。Example can be found here in the [previous section].

如何删除虚拟机规模集使用的前端 IP 配置:How to delete Frontend IP Configuration used by Virtual Machine Scale Set:

  1. 若要删除规模集使用的前端 IP 配置,需要首先删除引用前端 IP 配置的入站 NAT 池(一组入站 NAT 规则)。To delete the Frontend IP Configuration in use by the Scale Set, you need to first delete the inbound NAT pool (set of inbound NAT rules) referencing the frontend IP configuration. 有关如何删除入站规则的说明,请参阅上一部分。Instructions on how to delete the inbound rules can be found in the previous section.
  2. 删除引用前端 IP 配置的负载平衡规则。Delete the Load Balancing rule referencing the Frontend IP Configuration.
  3. 删除前端 IP 配置。Delete the Frontend IP Configuration.

如何删除虚拟机规模集使用的 Azure 负载均衡器:How to delete Azure Load Balancer used by Virtual Machine Scale Set:

  1. 若要删除规模集使用的前端 IP 配置,需要首先删除引用前端 IP 配置的入站 NAT 池(一组入站 NAT 规则)。To delete the Frontend IP Configuration in use by the Scale Set, you need to first delete the inbound NAT pool (set of inbound NAT rules) referencing the frontend IP configuration. 有关如何删除入站规则的说明,请参阅上一部分。Instructions on how to delete the inbound rules can be found in the previous section.

  2. 删除引用包含虚拟机规模集的后端池的负载平衡规则。Delete the Load Balancing rule referencing backend pool containing the Virtual Machine Scale Set.

  3. 从虚拟机规模集的网络配置文件中删除 loadBalancerBackendAddressPool 引用。Remove the loadBalancerBackendAddressPool reference from the network profile of the Virtual Machine Scale Set. 下面显示了一个使用 CLI 的完整示例:A full example using CLI is shown below:

 az vmss update
    --resource-group MyResourceGroup
    --name MyVMSS
    --remove virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].loadBalancerBackendAddressPools
 az vmss update-instances 
    --instance-ids "*" 
    --resource-group MyResourceGroup
    --name MyVMSS

最后,删除负载均衡器资源。Finally, delete the Load Balancer Resource.

后续步骤Next steps

若要详细了解 Azure 负载均衡器和虚拟机规模集,请阅读有关概念的详细信息。To learn more about Azure Load Balancer and Virtual Machine Scale Set, read more about the concepts.

Azure 负载均衡器和 Azure 虚拟机规模集Azure Load Balancer with Azure virtual machine scale sets