Creating a public load balancer using a template
This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.
An Azure load balancer is a Layer-4 (TCP, UDP) load balancer. The load balancer provides high availability by distributing incoming traffic among healthy service instances in cloud services or virtual machines in a load balancer set. Azure Load Balancer can also present those services on multiple ports, multiple IP addresses, or both.
You can configure a load balancer to:
- Load balance incoming Internet traffic to virtual machines (VMs). We refer to a load balancer in this scenario as an Internet-facing load balancer.
- Load balance traffic between VMs in a virtual network (VNet), between VMs in cloud services, or between on-premises computers and VMs in a cross-premises virtual network. We refer to a load balancer in this scenario as an internal load balancer (ILB).
- Forward external traffic to a specific VM instance.
The following tasks will be done in this scenario:
- Create a load balancer that receives network traffic on port 80 and send load-balanced traffic to virtual machines "web1" and "web2"
- Create NAT rules for remote desktop access/SSH for virtual machines behind the load balancer
- Create health probes
Deploy the template by using click to deploy
The sample template available in the public repository uses a parameter file containing the default values used to generate the scenario described above. To deploy this template using click to deploy, follow this link, click Deploy to Azure, replace the default parameter values if necessary, and follow the instructions in the portal.
Deploy the template by using PowerShell
To deploy the template you downloaded by using PowerShell, follow the steps below.
If you have never used Azure PowerShell, see How to Install and Configure Azure PowerShell and follow the instructions all the way to the end to sign into Azure and select your subscription.
Run the New-AzResourceGroupDeployment cmdlet to create a resource group using the template.
New-AzResourceGroupDeployment -Name TestRG -Location uswest ` -TemplateFile 'https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-2-vms-loadbalancer-lbrules/azuredeploy.json' ` -TemplateParameterFile 'https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-2-vms-loadbalancer-lbrules/azuredeploy.parameters.json'
Deploy the template by using the Azure CLI
To deploy the template by using the Azure CLI, follow the steps below.
If you have never used Azure CLI, see Install and Configure the Azure CLI and follow the instructions up to the point where you select your Azure account and subscription.
Run the azure config mode command to switch to Resource Manager mode, as shown below.
azure config mode arm
Here is the expected output for the command above:
info: New mode is arm
From your browser, navigate to the Quickstart Template, copy the contents of the json file and paste into a new file in your computer. For this scenario, you would be copying the values below to a file named c:\lb\azuredeploy.parameters.json.
Run the azure group deployment create cmdlet to deploy the new load balancer by using the template and parameter files you downloaded and modified above. The list shown after the output explains the parameters used.
azure group create --name TestRG --location westus --template-file 'https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/201-2-vms-loadbalancer-lbrules/azuredeploy.json' --parameters-file 'c:\lb\azuredeploy.parameters.json'
For the JSON syntax and properties of a load balancer in a template, see Microsoft.Network/loadBalancers.