Edit

Create a global load balancer with cross-subscription backends

In this article, you learn how to create a global load balancer with cross-subscription backends.

A cross-subscription load balancer can reference a virtual network that resides in a different subscription other than the load balancers. This feature allows you to deploy a load balancer in one subscription and reference a virtual network in another subscription.

Prerequisites

  • Two Azure subscriptions. One subscription for the regional load balancer and its virtual network (Azure Subscription A) and another subscription for the global load balancer (Azure Subscription B).
  • An Azure account with active subscriptions. Create an account for free.
  • A regional load balancer deployed in Azure Subscription A.
  • Azure PowerShell installed locally or Azure Cloud Shell.

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 to create a connection with Azure.

Important

All of the code samples use example names and placeholders. Be sure to replace these values with the values from your environment. The values needing replacement are enclosed in angle brackets, like this: <example value>.

Sign in to Azure

By using Azure PowerShell, you sign in to Azure by using Connect-AzAccount, and change your subscription context by using Set-AzContext to Azure Subscription A. Then get the regional load balancer information by using Get-AzLoadBalancer and Get-AzLoadBalancerFrontendIpConfig. You need the Azure subscription ID, resource group name, and load balancer name from your environment.


# Sign in to Azure
Connect-AzAccount

# Set the subscription context to Azure Subscription A
Set-AzContext -Subscription '<Subscription ID of Subscription A>'     

# Get the regional load balancer information with Get-AzLoadBalancer
$rlb = @{
    Name = 'load-balancer-regional'
    ResourceGroupName = 'resource-group-a'
}
$rlbinfo = Get-AzLoadBalancer @rlb
$rlbfe = Get-AzLoadBalancerFrontendIpConfig -LoadBalancer $rlbinfo

Create a resource group

In this section, you create a resource group in Azure Subscription B. This resource group is for all of your resources associated with your load balancer.

By using Azure PowerShell, you switch the subscription context by using Set-AzContext and create a resource group by using New-AzResourceGroup.


# Set the subscription context to Azure Subscription B
Set-AzContext -Subscription '<Azure Subscription B>'  

# Create a resource group  
$rg = @{
    Name = 'resource-group-b'
    Location = 'eastus2'
}
New-AzResourceGroup @rg

Note

When you create the resource group for your global load balancer, use a Global load balancer home region.

Create a global load balancer

In this section, you create the resources needed for the global load balancer. The frontend of the global load balancer uses a global standard SKU public IP. Because Azure global Load Balancer doesn't support cross-subscription frontends, you deploy this public IP address in Azure Subscription B along with the global load balancer.

By using Azure PowerShell, you:

# Create global IP address for load balancer
$ip = @{
    Name = 'public-IP-global'
    ResourceGroupName = 'resource-group-b'
    Location = 'eastus2'
    Sku = 'Standard'
    Tier = 'Global'
    AllocationMethod = 'Static'
}
$publicIP = New-AzPublicIpAddress @ip

# Create frontend configuration
$fe = @{
    Name = 'front-end-config-global'
    PublicIpAddress = $publicIP
}
$feip = New-AzLoadBalancerFrontendIpConfig @fe

# Create backend address pool
$be = @{
    Name = 'backend-pool-global'
}
$bepool = New-AzLoadBalancerBackendAddressPoolConfig @be

# Create the load balancer rule
$rul = @{
    Name = 'HTTP-rule-global'
    Protocol = 'tcp'
    FrontendPort = '80'
    BackendPort = '80'
    FrontendIpConfiguration = $feip
    BackendAddressPool = $bepool
}
$rule = New-AzLoadBalancerRuleConfig @rul

# Create global load balancer resource
$lbp = @{
    ResourceGroupName = 'resource-group-b'
    Name = 'load-balancer-global'
    Location = 'eastus2'
    Sku = 'Standard'
    Tier = 'Global'
    FrontendIpConfiguration = $feip
    BackendAddressPool = $bepool
    LoadBalancingRule = $rule
}
$lb = New-AzLoadBalancer @lbp

Add load balancer frontends to global load balancer

In this section, you add a regional load balancer's frontend IP configuration as a backend address in the global load balancer's backend pool. Because the regional load balancers are in a different subscription than the global load balancer, this configuration is a cross-subscription backend configuration.

By using Azure PowerShell, you:


## Create the backend address configuration from the regional load balancer frontend ##
$rlbbaf = @{
    Name = 'backend-pool-config-regional'
    LoadBalancerFrontendIPConfigurationId = $rlbfe.Id
}
$beaddressconfigRLB = New-AzLoadBalancerBackendAddressConfig @rlbbaf

## Apply the backend address pool configuration for the global load balancer ##
$bepoolcr = @{
    ResourceGroupName = 'resource-group-b'
    LoadBalancerName = 'load-balancer-global'
    Name = 'backend-pool-global'
    LoadBalancerBackendAddress = $beaddressconfigRLB
}
Set-AzLoadBalancerBackendAddressPool @bepoolcr

Next steps