Hi everyone,

In this post, I will show you how to create and configure Azure Load Balancer. Load Balancer is a service in Azure that provides you traffic balancing between few VMs that have same function, like a web server. Although you can provision many different virtual network appliances, such as Barracuda, F5, Kemp, Azure Services are in most of the cases better solution.

If you decided to use Azure portal, you need to click to Create a resource in left menu and find Load Balancer as a resource. Once you find resource in marketplace, you need to select resource for deployment. On the creation page you need to define following parameters:

  • Load Balancer name
  • Load Balancer typePublic or Internal
    • Public handles outside request
    • Internal handles request from virtual network
  • Load Balancer SKU
  • IP address(for public load balancer)
  • Resource group
  • Location

Once we created load balancer, we need to be configure it before it becomes fully functional. You need to create:

  • Frontend IP configuration
  • Backend pools
  • Health probes
  • Load balancing rules

Frontend IP configuration

If you don’t need more than one public IP address associated to the Load Balancer, you can skip this configuration, because public IP address that is created during Load Balancer creating process is already configured.

Backend pools

Backend pools define list of the virtual machines to which traffic needs to be forwarded. You can select between availability set, single virtual machine or virtual machine scale set. In Azure portal, select previous load balancer, click to Backend Pools and then click to Add. Then you can configure backend pools.

Health probes

Health probes need to be configured in order to have load balancer check whether virtual machines are “live” and if traffic can be forwarded to them. In Azure portal, select previous load balancer, click to Health Probes and then click to Add. Then you need to define name, port and protocol combination that needs to be checked, interval of checking and number of unsuccessful checks before load balancer removes virtual machine from balancing. For example, if you host web application on virtual machines, you can check TCP/80 to ensure that virtual machine can serve application.

Load balancing rules

At the end, you need to define rules. In general, rule is a combination of all previously configured parameters. In rule you need to define what Frontend IP address and port/protocol combination will be used, which backend port and backend pool will be used and what health probe will be used for testing backend virtual machines. Additionally, you can configure session persistence and whether Floating IP will be configured.

Now, you can start to use Azure Load Balancer.

If you want to use PowerShell to create Load Balancer, you need to run the following script that will create resource group and public load balancer with basic configuration.

# Define variables
$Location          = 'North Europe'
$RGName            = "TechTrainer-Networking"
$LoadBalancerName  = "TechTrainer-LB"
$LBFrontendName    = "DefaultFrontend"
$LBBackendPoolName = "BackendPoolServers"
$LBProbeName       = "BackendHTTPProbe"
$LBRuleName        = "DefaultLBRule"

# Create a resource group for networking resources
New-AzResourceGroup -Name $RGName -Location $Location

# Create a public IP for load balancer
$LoadBalancerPublicIP = New-AzPublicIpAddress -ResourceGroupName $RGName -Location $Location -AllocationMethod "Static" -Name "TechTrainer-LB-ip"

# Create a front-end IP configuration
$FrontendIP = New-AzLoadBalancerFrontendIpConfig -Name $LBFrontendName -PublicIpAddress $LoadBalancerPublicIP

# Create the back-end address pool
$BackendPool = New-AzLoadBalancerBackendAddressPoolConfig -Name $LBBackendPoolName

# Creates a load balancer probe on port 80
$LoadBalancerProbe = New-AzLoadBalancerProbeConfig -Name $LBProbeName -Protocol Http -Port 80 -RequestPath / -IntervalInSeconds 360 -ProbeCount 5

# Creates a load balancer rule for port 80
$LoadBalancerRule = New-AzLoadBalancerRuleConfig -Name $LBRuleName -Protocol Tcp -Probe $LoadBalancerProbe -FrontendPort 80 -BackendPort 80 -FrontendIpConfiguration $FrontendIP -BackendAddressPool $BackendPool

# Create a load balancer.
$lb = New-AzLoadBalancer -ResourceGroupName $RGName -Name $LoadBalancerName -Location $Location -FrontendIpConfiguration $FrontendIP -BackendAddressPool $BackendPool -Probe $LoadBalancerProbe -LoadBalancingRule $LoadBalancerRule

Cheers!

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.