|
| 1 | +--- |
| 2 | +title: Create a global load balancer with cross-subscription backends |
| 3 | +titleSuffix: Azure Load Balancer |
| 4 | +description: Learn how to create a global load balancer with cross-subscription backends by connecting a virtual network in a subscription to a load balancer in a different subscription. |
| 5 | +services: load-balancer |
| 6 | +author: mbender-ms |
| 7 | +ms.service: load-balancer |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 05/24/2024 |
| 10 | +ms.author: mbender |
| 11 | +ms.custom: |
| 12 | +--- |
| 13 | + |
| 14 | +# Create a global load balancer with cross-subscription backends |
| 15 | + |
| 16 | +In this article, you learn how to create a global load balancer with cross-subscription backends. |
| 17 | + |
| 18 | +A [cross-subscription internal load balancer (ILB)](cross-subscription-load-balancer-overview.md) 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. |
| 19 | + |
| 20 | +[!INCLUDE [load-balancer-cross-subscription-preview](../../includes/load-balancer-cross-subscription-preview.md)] |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +# [Azure PowerShell](#tab/azurepowershell) |
| 25 | + |
| 26 | +- Two Azure subscriptions. |
| 27 | +- An Azure account with active subscriptions. [Create an account for free](https://azure.microsoft.com/free/) |
| 28 | +- A global public IP address deployed in **Azure Subscription A**. |
| 29 | +- A regional load balancer deployed in **Azure Subscription B**. |
| 30 | +- Azure PowerShell installed locally or Azure Cloud Shell. |
| 31 | + |
| 32 | +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. |
| 33 | + |
| 34 | +> [!IMPORTANT] |
| 35 | +> All of the code samples will use example names and placeholders. Be sure to replace these with the values from your environment. |
| 36 | +> The values needing replacement will be enclosed in angle brackets, like this: `<example value>`. |
| 37 | +> |
| 38 | + |
| 39 | +# [Azure CLI](#tab/azurecli/) |
| 40 | + |
| 41 | +- Two Azure subscriptions. One subscription for the virtual network (**Azure Subscription A**) and another subscription for the load balancer(**Azure Subscription B**). |
| 42 | +- An Azure account with active subscriptions. [Create an account for free](https://azure.microsoft.com/free/) |
| 43 | +- A global public IP address deployed in **Azure Subscription A**. |
| 44 | +- A regional load balancer deployed in **Azure Subscription B**. |
| 45 | + |
| 46 | +[!INCLUDE [azure-cli-prepare-your-environment.md](~/reusable-content/azure-cli/azure-cli-prepare-your-environment-no-header.md)] |
| 47 | + |
| 48 | +If you choose to install and use the CLI locally, this quickstart requires Azure CLI version 2.60 or later. To find the version, run az --version. If you need to install or upgrade, see Install the Azure CLI. |
| 49 | + |
| 50 | +> [!IMPORTANT] |
| 51 | +> All of the code samples will use example names and placeholders. Be sure to replace these with the values from your environment. |
| 52 | +> The values needing replacement will be enclosed in angle brackets, like this: `<example value>`. |
| 53 | +
|
| 54 | +--- |
| 55 | + |
| 56 | +## Sign in to Azure |
| 57 | + |
| 58 | +# [Azure PowerShell](#tab/azurepowershell) |
| 59 | + |
| 60 | +With Azure PowerShell, you sign into Azure with [`Connect-AzAccount`](/powershell/module/az.accounts/connect-azaccount), and change your subscription context with [`Set-AzContext`](/powershell/module/az.accounts/set-azcontext) to **Azure Subscription A**. Then get the regional load balancer information with [`Get-AzLoadBalancer`](/powershell/module/az.network/get-azloadbalancer) and [`Get-AzLoadBalancerFrontendIpConfig](/powershell/module/az.network/get-azloadbalancerfrontendipconfig). You need the Azure subscription ID, resource group name, and virtual network name from your environment. |
| 61 | + |
| 62 | + |
| 63 | +```azurepowershell |
| 64 | +
|
| 65 | +# Sign in to Azure |
| 66 | +Connect-AzAccount |
| 67 | +
|
| 68 | +# Set the subscription context to Azure Subscription A |
| 69 | +Set-AzContext -Subscription '<Azure Subscription A>' |
| 70 | +
|
| 71 | +# Get the Virtual Network information with Get-AzVirtualNetwork |
| 72 | +$rlb= @{ |
| 73 | + Name = '<regional load balancer name>' |
| 74 | + ResourceGroupName = '<Resource Group Subscription A>' |
| 75 | +} |
| 76 | +$RLB-info = Get-AzLoadBalancer @rlb |
| 77 | +$RLBFE = Get-AzLoadBalancerFrontendIpConfig @ RLB-info |
| 78 | +
|
| 79 | +``` |
| 80 | + |
| 81 | +# [Azure CLI](#tab/azurecli/) |
| 82 | + |
| 83 | +```azurecli |
| 84 | +
|
| 85 | +With Azure CLI, you'll sign into Azure with [az login](/cli/azure/reference-index#az-login), and change your subscription context with [`az account set`](/cli/azure/account#az_account_set) to **Azure Subscription A**. |
| 86 | +
|
| 87 | +```azurecli |
| 88 | +
|
| 89 | +# Sign in to Azure CLI and change subscription to Azure Subscription B |
| 90 | +Az login |
| 91 | +Az account set –subscription <Azure Subscription A> |
| 92 | +``` |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Create a resource group |
| 97 | + |
| 98 | +In this section, you create a resource group in **Azure Subscription B**. This resource group is for all of your resources associate with your load balancer. |
| 99 | + |
| 100 | +# [Azure PowerShell](#tab/azurepowershell) |
| 101 | + |
| 102 | +With Azure PowerShell, you switch the subscription context with [`Set-AzContext`](/powershell/module/az.accounts/set-azcontext) and create a resource group with [`New-AzResourceGroup`](/powershell/module/az.resources/new-azresourcegroup). |
| 103 | + |
| 104 | +```azurepowershell |
| 105 | +
|
| 106 | +# Set the subscription context to Azure Subscription B |
| 107 | +Set-AzContext -Subscription '<Azure Subscription B>' |
| 108 | +
|
| 109 | +# Create a resource group |
| 110 | +$rg = @{ |
| 111 | + Name = 'myResourceGroupLB' |
| 112 | + Location = 'westus' |
| 113 | +} |
| 114 | +New-AzResourceGroup @rg |
| 115 | +``` |
| 116 | +> [!NOTE] |
| 117 | +> When create the resource group for your load balancer, use the same Azure region as the virtual network in **Azure Subscription A**. |
| 118 | +
|
| 119 | +# [Azure CLI](#tab/azurecli/) |
| 120 | + |
| 121 | +With Azure CLI, you switch the subscription context with [`az account set`](/cli/azure/account#az_account_set) and create a resource group with [`az group create`](/cli/azure/group#az_group_create). |
| 122 | + |
| 123 | +```azurecli |
| 124 | +# Create a resource group in Azure Subscription B |
| 125 | +az group create --name 'myResourceGroupLB' --location westus |
| 126 | +``` |
| 127 | + |
| 128 | +> [!NOTE] |
| 129 | +> When create the resource group for your load balancer, use the same Azure region as the virtual network in **Azure Subscription A**. |
| 130 | +
|
| 131 | +--- |
| 132 | + |
| 133 | +## Create a global load balancer |
| 134 | + |
| 135 | +In this section, you create the resources needed for the cross-region load balancer. |
| 136 | +A global standard sku public IP is used for the frontend of the cross-region load balancer. |
| 137 | + |
| 138 | +# [Azure PowerShell](#tab/azurepowershell) |
| 139 | + |
| 140 | +With Azure PowerShell, you: |
| 141 | + |
| 142 | +- Use [`New-AzPublicIpAddress`](/powershell/module/az.network/new-azpublicipaddress) to create the public IP address. |
| 143 | +- Create a frontend IP configuration with [`New-AzLoadBalancerFrontendIpConfig`](/powershell/module/az.network/new-azloadbalancerfrontendipconfig). |
| 144 | +- Create a backend address pool with [`New-AzLoadBalancerBackendAddressPoolConfig`](/powershell/module/az.network/new-azloadbalancerbackendaddresspoolconfig). |
| 145 | +- Create a load balancer rule with [`Add-AzLoadBalancerRuleConfig`](/powershell/module/az.network/add-azloadbalancerruleconfig). |
| 146 | +- Create a global load Balancer with [`New-AzLoadBalancer`](/powershell/module/az.network/new-azloadbalancer). |
| 147 | + |
| 148 | +```azurepowershell |
| 149 | +# Create global IP address for load balancer |
| 150 | +$ip = @{ |
| 151 | + Name = 'myPublicIP-CR' |
| 152 | + ResourceGroupName = ‘ Resource Group B’ |
| 153 | + Location = 'eastus2' |
| 154 | + Sku = 'Standard' |
| 155 | + Tier = 'Global' |
| 156 | + AllocationMethod = 'Static' |
| 157 | +} |
| 158 | +$publicIP = New-AzPublicIpAddress @ip |
| 159 | +
|
| 160 | +# Create frontend configuration |
| 161 | +$fe = @{ |
| 162 | + Name = 'myFrontEnd-CR' |
| 163 | + PublicIpAddress = $publicIP |
| 164 | +} |
| 165 | +$feip = New-AzLoadBalancerFrontendIpConfig @fe |
| 166 | +
|
| 167 | +# Create backend address pool |
| 168 | +$be = @{ |
| 169 | + Name = 'myBackEndPool-CR' |
| 170 | +} |
| 171 | +$bepool = New-AzLoadBalancerBackendAddressPoolConfig @be |
| 172 | +
|
| 173 | +# Create the load balancer rule |
| 174 | +$rul = @{ |
| 175 | + Name = 'myHTTPRule-CR' |
| 176 | + Protocol = 'tcp' |
| 177 | + FrontendPort = '80' |
| 178 | + BackendPort = '80' |
| 179 | + FrontendIpConfiguration = $feip |
| 180 | + BackendAddressPool = $bepool |
| 181 | +} |
| 182 | +$rule = New-AzLoadBalancerRuleConfig @rul |
| 183 | +
|
| 184 | +# Create cross-region load balancer resource |
| 185 | +$lbp = @{ |
| 186 | + ResourceGroupName = ‘ Resource Group B’ |
| 187 | + Name = 'myLoadBalancer-CR' |
| 188 | + Location = ‘eastus2’ |
| 189 | + Sku = 'Standard' |
| 190 | + Tier = 'Global' |
| 191 | + FrontendIpConfiguration = $feip |
| 192 | + BackendAddressPool = $bepool |
| 193 | + LoadBalancingRule = $rule |
| 194 | +} |
| 195 | +$lb = New-AzLoadBalancer @lbp |
| 196 | +``` |
| 197 | + |
| 198 | +# [Azure CLI](#tab/azurecli/) |
| 199 | + |
| 200 | +With Azure CLI, you: |
| 201 | + |
| 202 | +- Create a cross-region load balancer with [`az network cross-region-lb create`](/cli/azure/network/az-network-cross-region-lb-rule-create). |
| 203 | +- Create a load balancer rule with [`az network cross-region-lb rule create`](/cli/azure/network/az-network-cross-region-lb-rule-create). |
| 204 | + |
| 205 | +```azurecli |
| 206 | +
|
| 207 | +# Create cross-region load balancer |
| 208 | +az network cross-region-lb create --name myLoadBalancer-CR --resource-group myResourceGroupLB-CR --frontend-ip-name myFrontEnd-CR --backend-pool-name myBackEndPool-CR |
| 209 | +
|
| 210 | +# create a load balancer rule |
| 211 | +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 |
| 212 | +
|
| 213 | +``` |
| 214 | +--- |
| 215 | + |
| 216 | +## Add load balancer frontends to cross-region load balancer |
| 217 | + |
| 218 | +In this section, you add a frontend IP configuration to the cross-region load balancer. |
| 219 | + |
| 220 | +# [Azure PowerShell](#tab/azurepowershell) |
| 221 | + |
| 222 | +With Azure PowerShell, you: |
| 223 | + |
| 224 | +- Use [`Set-AzLoadBalancerFrontendIpConfig`](/powershell/module/az.network/set-azloadbalancerfrontendipconfig) to add the regional load balancer frontend to the cross-region backend pool. |
| 225 | +- Use [`New-AzLoadBalancerBackendAddressConfig`](/powershell/module/az.network/new-azloadbalancerbackendaddressconfig) to create the backend address pool configuration for the load balancer. |
| 226 | + |
| 227 | +```azurepowershell |
| 228 | +
|
| 229 | +## Create the cross-region backend address pool configuration for region 2 ## |
| 230 | +$RLB-BAF = @{ |
| 231 | + Name = 'MyBackendPoolConfig-RLB' |
| 232 | + LoadBalancerFrontendIPConfigurationId = $RLBFE.Id |
| 233 | +} |
| 234 | +$beaddressconfigRLB = New-AzLoadBalancerBackendAddressConfig @region2ap |
| 235 | +
|
| 236 | +## Apply the backend address pool configuration for the cross-region load balancer ## |
| 237 | +$bepoolcr = @{ |
| 238 | + ResourceGroupName = ‘ Resource Group B’ |
| 239 | + LoadBalancerName = 'myLoadBalancer-CR' |
| 240 | + Name = 'myBackEndPool-CR' |
| 241 | + LoadBalancerBackendAddress = $beaddressconfigRLB |
| 242 | +} |
| 243 | +Set-AzLoadBalancerBackendAddressPool @bepoolcr |
| 244 | +
|
| 245 | +``` |
| 246 | + |
| 247 | +# [Azure CLI](#tab/azurecli/) |
| 248 | + |
| 249 | +With Azure CLI, you add the frontends you placed in variables in the backend pool of the cross-region load balancer with use [`az network cross-region-lb address-pool`](/powershell/module/az.network/az-network-cross-region-lb-address-pool). |
| 250 | + |
| 251 | +```azurecli |
| 252 | +
|
| 253 | +az network cross-region-lb address-pool address add \ |
| 254 | + --frontend-ip-address ‘/subscriptions/Subscription A/resourceGroups/rg-name/providers/Microsoft.Network/loadBalancers/RLB-name /frontendIPConfigurations/RLB-LB Frontend Name’ |
| 255 | + --lb-name myLoadBalancer-CR \ |
| 256 | + --name myFrontEnd-R2 \ |
| 257 | + --pool-name myBackEndPool-CR \ |
| 258 | + --resource-group myResourceGroupLB-CR |
| 259 | +``` |
| 260 | + |
| 261 | +## Next steps |
| 262 | + |
| 263 | +> [!div class="nextstepaction"] |
| 264 | +> [Create a cross-subscription internal load balancer](./cross-subscription-howto-internal-load-balancer.md) |
| 265 | +
|
| 266 | + |
| 267 | + |
| 268 | + |
| 269 | + |
| 270 | + |
| 271 | + |
| 272 | + |
0 commit comments