Creating load balancing rules – Configuring Load Balancing
Creating load balancing rules
Load balancing rules define how the traffic is distributed to the VMs inside the backend pool. When you create a new rule, you define the frontend IP configuration for incoming traffic, the backend IP pool that receives the traffic, and the required source and destination ports. The rule that we are going to create listens to port 80 at the frontend. The rule then sends the network traffic to the backend pool, also on port80. To create the rule, take the following steps:
- Open the Load Balancer resource.
- Under Settings, select Load balancing rules, and then select Add:

Figure 16.11 – Load balancing rules
- Enter PacktLoadBalancerRule for Name, set IP Version as IPv4, select PacktLBFEName for Frontend IP Address, select PackLBBackendPool for Backend pool, set Protocol as TCP, Port as 80, Backend port as 80, select PacktHealthProbe (HTTP:80) for Health probe, set Session persistence as None, leave Idle timeout (minutes) as the default, and leave Floating IP as the default (normally Disabled). Click Add:

Figure 16.12 – Adding a load balancing rule
Now that your load balancer is all configured, you are ready to start testing it to confirm it works as expected. Next, we will walk through how to go about testing your load balancer.
Testing the load balancer
To test the VMs properly, we are going to install Internet Information Services (IIS) on the PacktLBVM1 and PacktLBVM2 VMs using PowerShell. Then, we can use the PacktLBVMTest VM to test the load balancer by calling its private IP address. First, we need to obtain the private IP address of the load balancer. Take the following steps:
- Open the Load Balancer resource.
- Under Settings, select Frontend IP configuration, and copy the private IP address as follows:

Figure 16.13 – Identifying your private IP
- Now, we need to connect to the PacktLBVM1 and PacktLBVM2 VM using an RDP session on the public IPs and install IIS and a testing web page on it. Connect to both the VMs, open the PowerShell console, and paste and run the following PowerShell script:
#Install IIS
Install-WindowsFeature -name Web-Server -IncludeManagementTools
#Remove default htm file remove-item C:\inetpub\wwwroot\iisstart.htm #Add custom htm file
Add-Content -Path “C:\inetpub\wwwroot\iisstart.htm” -Value $(“Hello World from ” + $env:computername)
Top Tip
Instead of connecting to each VM and configuring IIS services, you can also use Azure Automation Workbook or Azure VM PowerShell Script Extension.
- Next, connect to the PacktLBVMTest VM using RDP as well, open a browser session (such as Internet Explorer), and navigate to the private IP address of the load balancer obtained from Step 2. Refresh the browser a couple of times to see the load balancer distributing the requests over the two VMs, as the following screenshot shows:

Figure 16.14 – Testing the load balancer
You have now successfully deployed your first ILB within Azure, and you now understand how load balancing is used to distribute access to workloads as needed, as well as the service catering to HA requirements for inaccessible workloads. You have also learned that ILBs are for traffic that is internal or private to your VNets and restricted from public access, and public load balancers are used to load balance public-facing workloads. Next, we will explore the configuration of a public load balancer.