Configuring a public load balancer – Configuring Load Balancing


Configuring a public load balancer

In this section, we are going to create a public load balancer using the Azure command-line interface (CLI). You can copy the code snippets in Azure Cloud Shell, which is accessible from the Azure portal. The full script for creating the public load balancer can be downloaded from GitHub as well. Refer to the location specified in the Technical requirements section at the beginning of this chapter.

Creating the public load balancer

To create the public load balancer, a series of steps need to be taken. In the upcoming sections, we will create the public load balancer with all the necessary components:

  1. Navigate to the Azure portal by opening https://portal.azure.com.
  2. Click the Azure CLI icon at the top right of the Azure portal to open an Azure CLI instance:

Figure 16.15 – Opening the Azure CLI

  1. If you have never used the CLI before, you will be required to set up storage for this; follow the prompts on the screen to configure your container on a storage account.
  2. When asked for the environment, you can select PowerShell; if you decide you would like to use Bash, then enter the following, which will open PowerShell in the Bash terminal, and press Enter:

pwsh

Top Tip

You should note that when using PowerShell within Bash, you cannot define variables in the Linux Bash format.

  1. You may reuse the resource group from the previous exercise, or should you wish to create a new one, you can run the command as follows, using AZ104-PublicLoadBalancer as an example resource group name:

#Create a resource group

az group create –name AZ104-PublicLoadBalancer –location westeurope

Top Tip

Please note, when pasting into the CLI, you need to right-click and paste; you can’t use keyboard shortcuts such as Ctrl + V or Cmd + V.

  1. Next, we are going to configure a public IP address for the load balancer to access it from the internet. A standard load balancer only supports standard public IP addresses, as shown in the following code:

#Create a public IP address

az network public-ip create –resource-group AZ104-PublicLoadBalancer –name PacktPublicIP –sku standard

  1. Now, we are going to create the load balancer and the components, including a frontend IP pool, a backend IP pool, a health probe, and a load balancer rule. To create the load balancer, add the following code:

#Create the Load Balancer az network lb create `

–resource-group AZ104-PublicLoadBalancer --name PacktPublicLoadBalancer

–sku standard `

–public-ip-address PacktPublicIP --frontend-ip-name PacktFrontEnd –backend-pool-name PacktBackEndPool

Top Tip

The ‘ (tilde) symbol in your Azure CLI commands allows you to split your commands and run them on the next line for more readable code.

  1. All VM instances are checked by the health probe to define whether they are healthy enough to send network traffic to them. VM instances that are unhealthy are removed from the load balancer until the probe check determines that they are healthy again. To create the health probe, add the following code:

#Create the health probe

az network lb probe create `

–resource-group AZ104-PublicLoadBalancer `

–lb-name PacktPublicLoadBalancer `

–name PacktHealthProbe `

–protocol tcp `

–port 80

  1. The load balancer rule defines the frontend IP configuration for the incoming traffic and the backend IP pool to receive the traffic, together with the required source and destination ports. To create the load balancing rule, run the code as follows:

#Create the Load Balancer rule

az network lb rule create `

–resource-group AZ104-PublicLoadBalancer --lb-name PacktPublicLoadBalancer –name PacktHTTPRule --protocol tcp

–frontend-port 80 `

–backend-port 80 `

–frontend-ip-name PacktFrontEnd `

–backend-pool-name PacktBackEndPool ` –probe-name PacktHealthProbe

Now that your load balancer is deployed, we are ready to move on to the deployment of the VNet, which we will look at next.

Leave a Reply

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