A global load balancer ensures a service is available globally across multiple Azure regions. If one region fails, the traffic is routed to the next closest healthy regional load balancer.
In this tutorial, you learn how to:
- Create global load balancer.
- Create a backend pool containing two regional load balancers.
- Create a load balancer rule.
- Test the load balancer.
You can use the Azure portal, Azure CLI, or Azure PowerShell to complete this tutorial.
Prerequisites
- An Azure subscription. If you don't have an Azure subscription, create a trial subscription before you begin.
- Two standard sku Azure Load Balancers with backend pools deployed in two different Azure regions.
- An Azure subscription. If you don't have an Azure subscription, create a trial subscription before you begin.
- Two standard sku Azure Load Balancers with backend pools deployed in two different Azure regions.
- Azure CLI installed locally or Azure powerShell.
If you choose to install and use the CLI locally, this quickstart requires Azure CLI version 2.0.28 or later. To find the version, run az --version
. If you need to install or upgrade, see Install the Azure CLI. When running Azure CLI locally, you'll need to sign in with az login
to create a connection with Azure.
- An Azure subscription. If you don't have an Azure subscription, create a trial subscription before you begin.
- Two standard sku Azure Load Balancers with backend pools deployed in two different Azure regions.
- Azure PowerShell installed locally or Azure powerShell.
If you choose to install and use PowerShell locally, this article requires the Azure PowerShell module version 5.4.1 or later. Run Get-Module -ListAvailable Az
to find the installed version. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell locally, you also need to run Connect-AzAccount -Environment AzureChinaCloud
to create a connection with Azure.
Create global load balancer
In this section, you create a global load balancer with a public IP address, a frontend IP configuration, a backend pool with region load balancers added, and a load balancer rule.
Create the load balancer resource and other resources
Sign in to the Azure portal.
In the search box at the top of the portal, enter Load balancer. Select Load balancer in the search results.
In the Load balancer page, select Create.
In the Basics tab of the Create load balancer page, enter, or select the following information:
Setting |
Value |
Project details |
|
Subscription |
Select your subscription. |
Resource group |
Select Create new and enter CreateCRLBTutorial-rg in the text box. |
Instance details |
|
Name |
Enter myLoadBalancer-cr |
Region |
Select (Asia Pacific) China East. |
Type |
Select Public. |
SKU |
Leave the default of Standard. |
Tier |
Select Global |
Select Next: Frontend IP configuration at the bottom of the page.
In Frontend IP configuration, select + Add a frontend IP.
Enter LoadBalancerFrontend in Name in Add frontend IP address.
Select IPv4 or IPv6 for IP version.
In Public IP address, select Create new. Enter myPublicIP-cr in Name. Select Save for the Add Public IP Address Dialog.
Select Save.
Select Next: Backend pools at the bottom of the page.
In Backend pools, select + Add a backend pool.
Enter myBackendPool-cr in Name in Add backend pool.
In Load balancers, select myLoadBalancer-r1 or your first regional load balancer in the Load balancer pull-down box. Verify the Frontend IP configuration and IP address correspond with myLoadBalancer-r1.
Select myLoadBalancer-r2 or your second regional load balancer in the Load balancer pull-down box. Verify the Frontend IP configuration and IP address correspond with myLoadBalancer-r2.
Select Add.
Select Next: Inbound rules at the bottom of the page.
In Inbound rules, select + Add a load balancing rule.
In Add load balancing rule, enter or select the following information:
Setting |
Value |
Name |
Enter myHTTPRule-cr. |
IP Version |
Select IPv4 or IPv6 for IP Version. |
Frontend IP address |
Select LoadBalancerFrontend. |
Protocol |
Select TCP. |
Port |
Enter 80. |
Backend pool |
Select myBackendPool-cr. |
Session persistence |
Select None. |
Idle timeout (minutes) |
Enter or move the slider to 15. |
TCP reset |
Select Enabled. |
Floating IP |
Leave the default of Disabled. |
Select Add.
Select Review + create at the bottom of the page.
Select Create in the Review + create tab.
Note
Cross region load-balancer deployment is listed to specific home Azure regions. For the current list, see Home regions in Azure for cross region load balancer.
Create a resource group
An Azure resource group is a logical container into which Azure resources are deployed and managed.
Create a resource group with az group create:
- Named myResourceGroupLB-CR.
- In the chinanorth location.
az group create \
--name myResourceGroupLB-CR \
--location chinanorth
Create the global load balancer resource
Create a global load balancer with az network cross-region-lb create:
- Named myLoadBalancer-CR.
- A frontend pool named myFrontEnd-CR.
- A backend pool named myBackEndPool-CR.
az network cross-region-lb create \
--name myLoadBalancer-CR \
--resource-group myResourceGroupLB-CR \
--frontend-ip-name myFrontEnd-CR \
--backend-pool-name myBackEndPool-CR
Create the load balancer rule
A load balancer rule defines:
- Frontend IP configuration for the incoming traffic.
- The backend IP pool to receive the traffic.
- The required source and destination port.
Create a load balancer rule with az network cross-region-lb rule create:
- Named myHTTPRule-CR
- Listening on Port 80 in the frontend pool myFrontEnd-CR.
- Sending load-balanced network traffic to the backend address pool myBackEndPool-CR using Port 80.
- Protocol TCP.
az network cross-region-lb rule create \
--backend-port 80 \
--frontend-port 80 \
--lb-name myLoadBalancer-CR \
--name myHTTPRule-CR \
--protocol tcp \
--resource-group myResourceGroupLB-CR \
--backend-pool-name myBackEndPool-CR \
--frontend-ip-name myFrontEnd-CR
Create backend pool
In this section, you add two regional standard load balancers to the backend pool of the global load balancer.
Add the regional frontends to load balancer
In this section, you place the resource IDs of two regional load balancers frontends into variables, and then use the variables to add the frontends to the backend address pool of the global load balancer.
Retrieve the resource IDs with az network lb frontend-ip show.
Use az network cross-region-lb address-pool address add to add the frontends you placed in variables in the backend pool of the global load balancer:
region1id=$(az network lb frontend-ip show \
--lb-name myLoadBalancer-R1 \
--name myFrontEnd-R1 \
--resource-group CreatePubLBQS-rg-r1 \
--query id \
--output tsv)
az network cross-region-lb address-pool address add \
--frontend-ip-address $region1id \
--lb-name myLoadBalancer-CR \
--name myFrontEnd-R1 \
--pool-name myBackEndPool-CR \
--resource-group myResourceGroupLB-CR
region2id=$(az network lb frontend-ip show \
--lb-name myLoadBalancer-R2 \
--name myFrontEnd-R2 \
--resource-group CreatePubLBQS-rg-r2 \
--query id \
--output tsv)
az network cross-region-lb address-pool address add \
--frontend-ip-address $region2id \
--lb-name myLoadBalancer-CR \
--name myFrontEnd-R2 \
--pool-name myBackEndPool-CR \
--resource-group myResourceGroupLB-CR
Create a resource group
An Azure resource group is a logical container into which Azure resources are deployed and managed.
Create a resource group with New-AzResourceGroup.
$rg = @{
Name = 'MyResourceGroupLB-CR'
Location = 'chinanorth'
}
New-AzResourceGroup @rg
Create global load balancer resources
In this section, you create the resources needed for the global load balancer.
A global standard sku public IP is used for the frontend of the global load balancer.
`## Create global IP address for load balancer ##
$ip = @{
Name = 'myPublicIP-CR'
ResourceGroupName = 'MyResourceGroupLB-CR'
Location = 'chinanorth'
Sku = 'Standard'
Tier = 'Global'
AllocationMethod = 'Static'
}
$publicIP = New-AzPublicIpAddress @ip
## Create frontend configuration ##
$fe = @{
Name = 'myFrontEnd-CR'
PublicIpAddress = $publicIP
}
$feip = New-AzLoadBalancerFrontendIpConfig @fe
## Create backend address pool ##
$be = @{
Name = 'myBackEndPool-CR'
}
$bepool = New-AzLoadBalancerBackendAddressPoolConfig @be
## Create the load balancer rule ##
$rul = @{
Name = 'myHTTPRule-CR'
Protocol = 'tcp'
FrontendPort = '80'
BackendPort = '80'
FrontendIpConfiguration = $feip
BackendAddressPool = $bepool
}
$rule = New-AzLoadBalancerRuleConfig @rul
## Create global load balancer resource ##
$lbp = @{
ResourceGroupName = 'myResourceGroupLB-CR'
Name = 'myLoadBalancer-CR'
Location = 'chinanorth'
Sku = 'Standard'
Tier = 'Global'
FrontendIpConfiguration = $feip
BackendAddressPool = $bepool
LoadBalancingRule = $rule
}
$lb = New-AzLoadBalancer @lbp`
In this section, you add two regional standard load balancers to the backend pool of the global load balancer.
## Place the region one load balancer configuration in a variable ##
$region1 = @{
Name = 'myLoadBalancer-R1'
ResourceGroupName = 'CreatePubLBQS-rg-r1'
}
$R1 = Get-AzLoadBalancer @region1
## Place the region two load balancer configuration in a variable ##
$region2 = @{
Name = 'myLoadBalancer-R2'
ResourceGroupName = 'CreatePubLBQS-rg-r2'
}
$R2 = Get-AzLoadBalancer @region2
## Place the region one load balancer frontend configuration in a variable ##
$region1fe = @{
Name = 'MyFrontEnd-R1'
LoadBalancer = $R1
}
$R1FE = Get-AzLoadBalancerFrontendIpConfig @region1fe
## Place the region two load balancer frontend configuration in a variable ##
$region2fe = @{
Name = 'MyFrontEnd-R2'
LoadBalancer = $R2
}
$R2FE = Get-AzLoadBalancerFrontendIpConfig @region2fe
## Create the global backend address pool configuration for region 1 ##
$region1ap = @{
Name = 'MyBackendPoolConfig-R1'
LoadBalancerFrontendIPConfigurationId = $R1FE.Id
}
$beaddressconfigR1 = New-AzLoadBalancerBackendAddressConfig @region1ap
## Create the global backend address pool configuration for region 2 ##
$region2ap = @{
Name = 'MyBackendPoolConfig-R2'
LoadBalancerFrontendIPConfigurationId = $R2FE.Id
}
$beaddressconfigR2 = New-AzLoadBalancerBackendAddressConfig @region2ap
## Apply the backend address pool configuration for the global load balancer ##
$bepoolcr = @{
ResourceGroupName = 'myResourceGroupLB-CR'
LoadBalancerName = 'myLoadBalancer-CR'
Name = 'myBackEndPool-CR'
LoadBalancerBackendAddress = $beaddressconfigR1,$beaddressconfigR2
}
Set-AzLoadBalancerBackendAddressPool @bepoolcr
Test the load balancer
In this section, you test the global load balancer. You connect to the public IP address in a web browser. You stop the virtual machines in one of the regional load balancer backend pools and observe the failover.
Find the public IP address for the load balancer on the Overview screen. Select All services in the left-hand menu, select All resources, and then select myPublicIP-cr.
Copy the public IP address, and then paste it into the address bar of your browser. The default page of IIS Web server is displayed on the browser.
Stop the virtual machines in the backend pool of one of the regional load balancers.
Refresh the web browser and observe the failover of the connection to the other regional load balancer.
In this section, you test the global load balancer. You connect to the public IP address in a web browser. You stop the virtual machines in one of the regional load balancer backend pools and observe the failover.
To get the public IP address of the load balancer, use az network public-ip show:
az network public-ip show \
--resource-group myResourceGroupLB-CR \
--name PublicIPmyLoadBalancer-CR \
--query ipAddress \
--output tsv
Copy the public IP address, and then paste it into the address bar of your browser. The default page of IIS Web server is displayed on the browser.
Stop the virtual machines in the backend pool of one of the regional load balancers.
Refresh the web browser and observe the failover of the connection to the other regional load balancer.
In this section, you test the global load balancer. You connect to the public IP address in a web browser. You stop the virtual machines in one of the regional load balancer backend pools and observe the failover.
- Use Get-AzPublicIpAddress to get the public IP address of the load balancer:
$ip = @{
Name = 'myPublicIP-CR'
ResourceGroupName = 'myResourceGroupLB-CR'
}
Get-AzPublicIPAddress @ip | select IpAddress
Copy the public IP address, and then paste it into the address bar of your browser. The default page of IIS Web server is displayed on the browser.
Stop the virtual machines in the backend pool of one of the regional load balancers.
Refresh the web browser and observe the failover of the connection to the other regional load balancer.
Clean up resources
When no longer needed, delete the resource group, load balancer, and all related resources.
To do so, select the resource group CreateCRLBTutorial-rg that contains the resources and then select Delete.
When no longer needed, use the az group delete command to remove the resource group, load balancer, and all related resources.
az group delete \
--name myResourceGroupLB-CR
When no longer needed, you can use the Remove-AzResourceGroup command to remove the resource group, load balancer, and the remaining resources.
Remove-AzResourceGroup -Name 'myResourceGroupLB-CR'
Next steps
In this tutorial, you:
- Created a global load balancer.
- Added regional load balancers to the backend pool of the global load balancer.
- Created a load-balancing rule.
- Tested the load balancer.
For more information on global load balancer, see: