|
1 | 1 | ---
|
2 |
| -title: Azure Load Balancer NAT Pool to NAT Rule Migration |
3 |
| -description: Process for migrating NAT Pools to NAT Rules on Azure Load Balancer. |
| 2 | +title: Migrate from Inbound NAT rules version 1 to version 2 |
| 3 | +description: Learn how to migrate from Inbound NAT rules version 1 to version 2 in Azure Load Balancer. |
4 | 4 | services: load-balancer
|
5 |
| -author: mbrat2005 |
| 5 | +author: mbender-ms |
6 | 6 | ms.service: azure-load-balancer
|
7 | 7 | ms.topic: how-to
|
8 |
| -ms.date: 06/26/2024 |
9 |
| -ms.author: mbratschun |
10 |
| -ms.custom: template-how-to, engagement-fy23 |
| 8 | +ms.date: 08/22/2024 |
| 9 | +ms.author: mbender |
11 | 10 | ---
|
12 | 11 |
|
13 |
| -# Tutorial: Migrate from Inbound NAT Pools to NAT Rules |
| 12 | +# Migrate from Inbound NAT rules version 1 to version 2 |
14 | 13 |
|
15 |
| -Azure Load Balancer NAT Pools are the legacy approach for automatically assigning Load Balancer front end ports to each instance in a Virtual Machine Scale Set. [NAT Rules](inbound-nat-rules.md) on Standard SKU Load Balancers have replaced this functionality with an approach that is both easier to manage and faster to configure. |
| 14 | +An [inbound NAT rule](inbound-nat-rules.md) is used to forward traffic from a load balancer’s frontend to one or more instances in the backend pool. These rules provide a 1:1 mapping between the load balancer’s frontend IP address and backend instances. There are currently two versions of Inbound NAT rules, version 1 and version 2. |
16 | 15 |
|
17 |
| -## Why Migrate to NAT Rules? |
| 16 | +:::image type="content" source="media/load-balancer-nat-pool-migration/load-balancer-inbound-nat-rule-flow.png" alt-text="Diagram of load balancer inbound nat rules"::: |
| 17 | +## Version 1 |
18 | 18 |
|
19 |
| -NAT Rules provide the same functionality as NAT Pools, but have the following advantages: |
20 |
| -* NAT Rules can be managed using the Portal |
21 |
| -* NAT Rules can leverage Backend Pools, simplifying configuration |
22 |
| -* NAT Rules configuration changes apply more quickly than NAT Pools |
23 |
| -* NAT Pools cannot be used in conjunction with user-configured NAT Rules |
| 19 | +[Version 1](inbound-nat-rules.md) is the legacy approach for assigning an Azure Load Balancer’s frontend port to each backend instance. Rules are applied to the backend instance’s network interface card (NIC). For Virtual Machine Scale Sets (VMSS) instances, inbound NAT rules are automatically created/deleted as new instances are scaled up/down. |
24 | 20 |
|
25 |
| -## Migration Process |
| 21 | +## Version 2 |
26 | 22 |
|
27 |
| -The migration process will create a new Backend Pool for each Inbound NAT Pool existing on the target Load Balancer. A corresponding NAT Rule will be created for each NAT Pool and associated with the new Backend Pool. Existing Backend Pool membership will be retained. |
| 23 | +[Version 2](inbound-nat-rules.md) of Inbound NAT rules provide the same feature set as version 1, with extra benefits. |
28 | 24 |
|
29 |
| -> [!IMPORTANT] |
30 |
| -> The migration process removes the Virtual Machine Scale Set(s) from the NAT Pools before associating the Virtual Machine Scale Set(s) with the new NAT Rules. This requires an update to the Virtual Machine Scale Set(s) model, which may cause a brief downtime while instances are upgraded with the model. |
| 25 | +- Simplified deployment experience and optimized updates. |
| 26 | + - Inbound NAT rules now target the backend pool of the load balancer and no longer require a reference on the virtual machine's NIC. Previously on version 1, both the load balancer and the virtual machine's NIC needed to be updated whenever the Inbound NAT rule was changed. Version 2 only requires a single call on the load balancer’s configuration, resulting in optimized updates. |
| 27 | +- Easily retrieve port mapping between Inbound NAT rules and backend instances. |
| 28 | + - With the legacy offering, to retrieve the port mapping between an Inbound NAT rule and a virtual machine instance, the rule would need to be correlated with the virtual machine's NIC. Version 2 injects the port mapping between the rule and backend instance directly into the load balancer’s configuration. |
31 | 29 |
|
32 |
| -> [!NOTE] |
33 |
| -> Frontend port mapping to Virtual Machine Scale Set instances may change with the move to NAT Rules, especially in situations where a single NAT Pool has multiple associated Virtual Machine Scale Sets. The new port assignment will align sequentially to instance ID numbers; when there are multiple Virtual Machine Scale Sets, ports will be assigned to all instances in one scale set, then the next, continuing. |
| 30 | +## How do I know if I’m using version 1 of Inbound NAT rules? |
34 | 31 |
|
35 |
| -> [!NOTE] |
36 |
| -> Service Fabric Clusters take significantly longer to update the Virtual Machine Scale Set model (up to an hour). |
| 32 | +The easiest way to identify if your deployments are using version 1 of the feature is by inspecting the load balancer’s configuration. If either the `InboundNATPool` property or the `backendIPConfiguration` property within the `InboundNATRule` configuration is populated, then the deployment is version 1 of Inbound NAT rules. |
37 | 33 |
|
38 |
| -### Prerequisites |
| 34 | +## How to migrate from version 1 to version 2? |
39 | 35 |
|
40 |
| -* In order to migrate a Load Balancer's NAT Pools to NAT Rules, the Load Balancer SKU must be 'Standard'. To automate this upgrade process, see the steps provided in [Upgrade a Basic Load Balancer to Standard with PowerShell](upgrade-basic-standard-with-powershell.md). |
41 |
| -* Virtual Machine Scale Sets associated with the target Load Balancer must use either a 'Manual' or 'Automatic' upgrade policy--'Rolling' upgrade policy is not supported. For more information, see [Virtual Machine Scale Sets Upgrade Policies](../virtual-machine-scale-sets/virtual-machine-scale-sets-upgrade-policy.md) |
42 |
| -* Install the latest version of [PowerShell](/powershell/scripting/install/installing-powershell) |
43 |
| -* Install the [Azure PowerShell modules](/powershell/azure/install-azure-powershell) |
| 36 | +Prior to migrating it's important to review the following information: |
44 | 37 |
|
45 |
| -### Install the 'AzureLoadBalancerNATPoolMigration' module |
| 38 | +- Migrating to version 2 of Inbound NAT rules causes downtime to active traffic that is flowing through the NAT rules. Traffic flowing through [load balancer rules](components.md) or [outbound rules](components.md) aren't impacted during the migration process. |
| 39 | +- Plan out the max number of instances in a backend pool. Since version 2 targets the load balancer’s backend pool, a sufficient number of ports need to be allocated for the NAT rule’s frontend. |
| 40 | +- Each backend instance is exposed on the port configured in the new NAT rule. |
| 41 | +- Multiple NAT rules can’t exist if they have an overlapping port range or have the same backend port. |
| 42 | +- NAT rules and load balancing rules can’t share the same backend port. |
46 | 43 |
|
47 |
| -Install the module from the [PowerShell Gallery](https://www.powershellgallery.com/packages/AzureLoadBalancerNATPoolMigration) |
| 44 | +### Manual Migration |
| 45 | + |
| 46 | +The following three steps need to be performed to migrate to version 2 of inbound NAT rules |
| 47 | + |
| 48 | +1. Delete the version 1 of inbound NAT rules on the load balancer’s configuration. |
| 49 | +2. Remove the reference to the NAT rule on the virtual machine or virtual machine scale set configuration. |
| 50 | + 1. All virtual machine scale set instances need to be updated. |
| 51 | +3. Deploy version 2 of Inbound NAT rules |
| 52 | + |
| 53 | +### Virtual Machine |
| 54 | + |
| 55 | +# [Azure CLI](#tab/azure-cli) |
| 56 | + |
| 57 | +```azurecli |
| 58 | +
|
| 59 | +az network lb inbound-nat-rule delete -g MyResourceGroup --lb-name MyLoadBalancer --name NATRule |
| 60 | +
|
| 61 | +az network nic ip-config inbound-nat-rule remove -g MyResourceGroup --nic-name MyNic -n MyIpConfig --inbound-nat-rule MyNatRul |
| 62 | +
|
| 63 | +az network lb inbound-nat-rule create -g MyResourceGroup --lb-name MyLoadBalancer -n MyNatRule --protocol Tcp --frontend-port-range-start 201 --frontend-port-range-end 500 --backend-port 80 |
| 64 | +
|
| 65 | +``` |
| 66 | + |
| 67 | +# [PowerShell](#tab/powershell) |
| 68 | + |
| 69 | +```powershell |
| 70 | +
|
| 71 | +$slb = Get-AzLoadBalancer -Name "MyLoadBalancer" -ResourceGroupName "MyResourceGroup" |
| 72 | +
|
| 73 | +Remove-AzLoadBalancerInboundNatRuleConfig -Name "myinboundnatrule" -LoadBalancer $loadbalancer |
| 74 | +
|
| 75 | +Set-AzLoadBalancer -LoadBalancer $slb |
| 76 | +
|
| 77 | +$nic = Get-AzNetworkInterface -Name "myNIC" -ResourceGroupName "MyResourceGroup" |
| 78 | +
|
| 79 | +$nic.IpConfigurations[0].LoadBalancerInboundNatRule = $null |
| 80 | +
|
| 81 | +Set-AzNetworkInterface -NetworkInterface $nic |
48 | 82 |
|
49 |
| -```azurepowershell |
50 |
| -Install-Module -Name AzureLoadBalancerNATPoolMigration -Scope CurrentUser -Repository PSGallery -Force |
51 | 83 | ```
|
| 84 | +--- |
| 85 | + |
| 86 | + |
| 87 | +### Virtual Machine Scale Set |
52 | 88 |
|
53 |
| -### Use the module to upgrade NAT Pools to NAT Rules |
| 89 | +# [Azure CLI](#tab/azure-cli) |
54 | 90 |
|
55 |
| -1. Connect to Azure with `Connect-AzAccount` |
56 |
| -1. Find the target Load Balancer for the NAT Rules upgrade and note its name and Resource Group name |
57 |
| -1. Run the migration command |
| 91 | +```azurecli |
58 | 92 |
|
59 |
| -#### Example: specify the Load Balancer name and Resource Group name |
60 |
| - ```azurepowershell |
61 |
| - Start-AzNATPoolMigration -ResourceGroupName <loadBalancerResourceGroupName> -LoadBalancerName <LoadBalancerName> |
62 |
| - ``` |
| 93 | +az network lb inbound-nat-pool delete -g MyResourceGroup --lb-name MyLoadBalancer -n MyNatPool |
63 | 94 |
|
64 |
| -#### Example: pass a Load Balancer from the pipeline |
65 |
| - ```azurepowershell |
66 |
| - Get-AzLoadBalancer -ResourceGroupName -ResourceGroupName <loadBalancerResourceGroupName> -Name <LoadBalancerName> | Start-AzNATPoolMigration |
67 |
| - ``` |
| 95 | +az vmss update -g MyResourceGroup -n MyVMScaleSet --remove virtualMachineProfile.networkProfile.networkInterfaceConfigurations[0].ipConfigurations[0].loadBalancerInboundNatPools |
68 | 96 |
|
69 |
| -## Common Questions |
| 97 | +az vmss update-instances --instance-ids '*' --resource-group MyResourceGroup --name MyVMScaleSet |
| 98 | +
|
| 99 | +az network lb inbound-nat-rule create -g MyResourceGroup --lb-name MyLoadBalancer -n MyNatRule --protocol Tcp --frontend-port-range-start 201 --frontend-port-range-end 500 --backend-port 80 |
| 100 | +
|
| 101 | +``` |
70 | 102 |
|
71 |
| -### Will migration cause downtime to my NAT ports? |
| 103 | +# [PowerShell](#tab/powershell) |
| 104 | + |
| 105 | +```powershell |
| 106 | +
|
| 107 | +# Remove the Inbound NAT rule |
| 108 | +
|
| 109 | +$slb = Get-AzLoadBalancer -Name "MyLoadBalancer" -ResourceGroupName "MyResourceGroup" |
| 110 | +
|
| 111 | +Remove-AzLoadBalancerInboundNatPoolConfig -Name myinboundnatpool -LoadBalancer $slb |
| 112 | +
|
| 113 | +Set-AzLoadBalancer -LoadBalancer $slb |
| 114 | +
|
| 115 | +# Remove the Inbound NAT pool association |
| 116 | +
|
| 117 | +$vmss = Get-AzVmss -ResourceGroupName "MyResourceGroup" -VMScaleSetName "MyVMScaleSet" |
| 118 | +
|
| 119 | +$vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].loadBalancerInboundNatPools = $null |
| 120 | +
|
| 121 | +Update-AzVmss -ResourceGroupName $resourceGroupName -Name $vmssName -VirtualMachineScaleSet $vmss |
| 122 | +
|
| 123 | +# Upgrade all instances in the VMSS |
| 124 | +
|
| 125 | +Update-AzVmssInstance -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssName -InstanceId "*" |
| 126 | +``` |
| 127 | +--- |
| 128 | + |
| 129 | +## Migration with automation script for Virtual Machine Scale Set |
| 130 | + |
| 131 | +> [!NOTE] This script is designed to work if there is only one VMSS instance attached to your load balancer. |
| 132 | +
|
| 133 | +### Prerequisites |
| 134 | + |
| 135 | +Before beginning the migration process, ensure the following prerequisites are met: |
| 136 | + |
| 137 | +- The load balancer's SKU must be **Standard** to migrate a load balancer's NAT Pools to NAT Rules. To automate this upgrade process, see the steps provided in [Upgrade a Basic Load Balancer to Standard with PowerShell](upgrade-basic-standard-with-powershell.md). |
| 138 | +- The Virtual Machine Scale Sets associated with the target Load Balancer must use either a 'Manual' or 'Automatic' upgrade policy--'Rolling' upgrade policy isn't supported. For more information, see [Virtual Machine Scale Sets Upgrade Policies](/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-upgrade-policy). |
| 139 | +- Install the latest version of [PowerShell](/powershell/scripting/install/installing-powershell). |
| 140 | +- Install the [Azure PowerShell modules](/powershell/azure/install-azure-powershell). |
| 141 | + |
| 142 | +### Install the `AzureLoadBalancerNATPoolMigration` module |
| 143 | + |
| 144 | +With the following command, install the `AzureLoadBalancerNATPoolMigration` module from the PowerShell Gallery: |
| 145 | + |
| 146 | +```powershell |
| 147 | +# Install the AzureLoadBalancerNATPoolMigration module |
| 148 | +
|
| 149 | +Install-Module -Name AzureLoadBalancerNATPoolMigration -Scope CurrentUser -Repository PSGallery -Force |
| 150 | +``` |
72 | 151 |
|
73 |
| -Yes, because we must first remove the NAT Pools before we can create the NAT Rules, there will be a brief time where there is no mapping of the front end port to a back end port. |
| 152 | +### Upgrade NAT Pools to NAT Rules |
74 | 153 |
|
75 |
| -> [!NOTE] |
76 |
| -> Downtime for NAT'ed port on Service Fabric clusters will be significantly longer--up to an hour for a Silver cluster in testing. |
| 154 | +With the `azureLoadBalancerNATPoolMigration` module installed, upgrade your NAT Pools to NAT Rules with the following steps: |
77 | 155 |
|
78 |
| -### Do I need to keep both the new Backend Pools created during the migration and my existing Backend Pools if the membership is the same? |
| 156 | +1. Connect to Azure with `Connect-AzAccount`. |
| 157 | +2. Collect the names of the **target load balancer** for the NAT Rules upgrade and its **Resource Group** name. |
| 158 | +3. Run the migration command with your resource names replacing the placeholders of `<loadBalancerResourceGroupName>` and `<loadBalancerName>`: |
79 | 159 |
|
80 |
| -No, following the migration, you can review the new backend pools. If the membership is the same between backend pools, you can replace the new backend pool in the NAT Rule with an existing backend pool, then remove the new backend pool. |
| 160 | + ```powershell |
| 161 | + # Run the migration command |
| 162 | + |
| 163 | + Start-AzNATPoolMigration -ResourceGroupName <loadBalancerResourceGroupName> -LoadBalancerName <loadBalancerName> |
| 164 | + |
| 165 | + ``` |
81 | 166 |
|
82 | 167 | ## Next steps
|
83 | 168 |
|
|
0 commit comments