title | description | services | documentationcenter | author | manager | editor | tags | ms.assetid | ms.service | ms.devlang | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CLI Example - Load balance traffic to VMs for high availability - Azure | Microsoft Docs |
This Azure CLI script example shows how to load balance traffic to VMs for high availability |
load-balancer |
load-balancer |
KumudD |
jeconnoc |
tysonn |
load-balancer |
azurecli |
sample |
infrastructure |
04/20/2018 |
kumud |
This Azure CLI script example creates everything needed to run several Ubuntu virtual machines configured in a highly available and load balanced configuration. After running the script, you will have three virtual machines, joined to an Azure Availability Set, and accessible through an Azure Load Balancer.
[!INCLUDE sample-cli-install]
[!INCLUDE quickstarts-free-trial-note]
[!code-azurecli-interactivemain]
Run the following command to remove the resource group, VM, and all related resources.
az group delete --name myResourceGroup
This script uses the following commands to create a resource group, virtual machine, availability set, load balancer, and all related resources. Each command in the table links to command specific documentation.
Command | Notes |
---|---|
az group create | Creates a resource group in which all resources are stored. |
az network vnet create | Creates an Azure virtual network and subnet. |
az network public-ip create | Creates a public IP address with a static IP address and an associated DNS name. |
az network lb create | Creates an Azure load balancer. |
az network lb probe create | Creates a load balancer probe. A load balancer probe is used to monitor each VM in the load balancer set. If any VM becomes inaccessible, traffic is not routed to the VM. |
az network lb rule create | Creates a load balancer rule. In this sample, a rule is created for port 80. As HTTP traffic arrives at the load balancer, it is routed to port 80 one of the VMs in the LB set. |
az network lb inbound-nat-rule create | Creates load balancer Network Address Translation (NAT) rule. NAT rules map a port of the load balancer to a port on a VM. In this sample, a NAT rule is created for SSH traffic to each VM in the load balancer set. |
az network nsg create | Creates a network security group (NSG), which is a security boundary between the internet and the virtual machine. |
az network nsg rule create | Creates an NSG rule to allow inbound traffic. In this sample, port 22 is opened for SSH traffic. |
az network nic create | Creates a virtual network card and attaches it to the virtual network, subnet, and NSG. |
az vm availability-set create | Creates an availability set. Availability sets ensure application uptime by spreading the virtual machines across physical resources such that if failure occurs, the entire set is not effected. |
az vm create | Creates the virtual machine and connects it to the network card, virtual network, subnet, and NSG. This command also specifies the virtual machine image to be used and administrative credentials. |
az group delete | Deletes a resource group including all nested resources. |
For more information on the Azure CLI, see Azure CLI documentation.
Additional Azure Networking CLI script samples can be found in the Azure Networking documentation.