DEV Community

Abiola Omiyale
Abiola Omiyale

Posted on • Updated on

Setting-Up A Basic Azure Load Balancer & Availability Sets

In this project, I will show you how to create and link the following resources on the Azure cloud platform.

Image description

  1. Provision an Azure virtual machine with an Ubuntu OS image.
  2. Availability sets 
  3. Install Apache webserver on the Azure virtual machine (Cloud Init). 
  4. Load Balancer

To carry out a reproduction of the same projects in this task, you can create an Azure account and have access to myriads of resources to play with. (Note : This is not an affiliate or sponsored ad for Azure.)

Image description

1 Provision an Azure virtual machine with an Ubuntu OS image

From the Azure home portal, locate and click the all resources button to see all the available resources you can work with on your subscription. 
Better still, we can always search for the resource by name in the global search bar (e.g., searching for virtual machines will bring out the virtual machine resource).

Image description (IMAGE 1)

An Azure virtual machine gives you the flexibility of virtualization without having to buy and maintain the physical hardware that runs it. However, you still need to maintain the virtual machine by performing tasks, such as configuring, patching, and installing the software that runs on it.

For more information on Azure Virtual machines: https://learn.microsoft.com/en-us/azure/virtual-machines/overview

Click on the create virtual machines button to launch the creation process for Azure Virtual Machines.
Image description (IMAGE 2)

Image description (IMAGE 3)

2 Availability Set
An Availability Set is a logical grouping capability for isolating VM resources from each other when they're deployed. Azure makes sure that if a hardware or software failure happens, only a subset of your VMs are impacted and your overall solution stays operational. Availability sets are essential for building reliable cloud solutions. For more information,see: https://learn.microsoft.com/en-us/azure/virtual-machines/availability#virtual-machines-scale-sets

For example, in a house we have rooms 1 & 2; when you deploy your virtual machines into an availability set, Azure deploys the virtual machines into separate houses, such that if there is a disaster in room 1, it won't have an effect on room 2. The two rooms will only be down at the same time when the house (room 1 & room 2) is impacted by the disaster. 
There are various availability options to help with disaster recovery on Azure: https://learn.microsoft.com/en-us/azure/virtual-machines/availability

Image description (IMAGE 4)

Image description

We can create an availability set as a stand-alone resource and attach and assign our virtual machines to the created availability sets. However, in this project, the availability sets will be created during the virtual machine instance creation (refer to image 3, where we launched the virtual machine resources creation).In the availability options, you select the drop down menu and select the availability sets.

Click the "create new availability" button to create a new availability set.
Image description (Image 5).

The virtual machine creation process continues. Virtual machine OS Image: The OS image determines what purpose the virtual machine serves. You can provision a virtual machine as a Windows desktop, a Windows server, or a Linux server with various Linux distributions. For more information, see: https://learn.microsoft.com/en-us/azure/virtual-machines/overview#distributions

In the Image tab, select See all images to see all the available images on the Azure marketplace. (For this project, we will be using the Ubuntu Server 20.04 LTS-Gen2)
Image description(IMAGE 6)

VM SIZE: Determine the type of virtual machine we get and the operations that can be performed on it. For more information, see:
Image description (IMAGE 7)

Clicking the "See all sizes" option for the Virtual Machine size option shows all the sizes available to select in your subscription.
Image description(IMAGE 8)-You can filter the VM cost by using the top/down toggle button).

In another project, we will generate an SSH key for logging into a Linux server

In the public inbound ports, select the allowed ports. In the allowed inbound ports (HTTPS 80—this will allow users to access the webserver webpages; Port 22—to allow a user to log into the webserver). (This settings can be controlled from the Network security group)
Image description (IMAGE 9)

For the selection of the virtual machine OS disks (for this project we will use a standard HDD ). Azure charges differently based on the type of disk you are using (Ultra Disk, Premium Disk, or Standard Disk ). For more information, see: https://learn.microsoft.com/en-us/azure/virtual-machines/disks-types

In the networking tab, we will use the virtual network (VNET) and subnet automatically created by the Azure wizard for this project (Note: we can also create the VNET and subnet as standalone resources, and add the VM to it).

Image description (IMAGE 10)

This time we won't use the Azure wizard to automatically create a load balancer. We will create the load balancer as a stand-alone resource after completing the set up of the virtual machines and the availability sets.
Image description (IMAGE 11)

3 ** **Install Apache webserver on the Azure virtual machine (Cloud Init). 
For custom data & cloud init, we will use a bash script to set-up a webserver (apache) during the virtual machine. For more information on cloud init:
Image description (IMAGE 12)

In the custom data box input this bash script. :

#!/bin/sh
sudo apt install apache2 -y
Enter fullscreen mode Exit fullscreen mode

After the setup has been validated, create the VM. 
Image description (Image 13)

When the VM has successfully been created, with the created VM attached public IP (51.142.119.100) we created in the network wizard tab, do this to confirm if the Apache webserver was successfully launched.
Image description (Note : Port 80 (HTTP) was opened during the VM creation process from Image so we can access the webserver over the internet. Access to and from the VM is configured in the Network security group tab of the networking section as shown in IMAGE 9.
Image description (IMAGE 14)

We don't need a public IP for the VM, so we will disable the public IP currently attached to the VM. As we will be attaching a load balancer to the VM, the IP of the load balancer will sit in front of the virtual machines.
Image description (IMAGE 15)

Image description (IMAGE 16)

Image description (IMAGE 17)

Image description (Image 18) (Use the toggle button to disassociate from the Public IP)

We add another virtual machine to the same availability set as the first one.
Image description (IMAGE 19)

In the networking tab we add the virtual machine to the same virtual network(VNET), as the first virtual machine. Make certain that it is provisioned in the same region and virtual network as the first virtual machine, if not you won't be able to add it to the basic load balancer.
Image description (IMAGE 20) (We will disable the public IP from setup wizard this time)

Image description(IMAGE 21) (the second virtual machine in the availability set.

You can confirm the availability setup of the virtual machine from the availability and scaling section.
Image description (IMAGE 22)

4 *Load Balancer *

Load balancing refers to evenly distributing load (incoming network traffic) across a group of backend resources or servers.

Azure Load Balancer operates at layer 4 of the Open Systems Interconnection (OSI) model. It's the single point of contact for clients. Load balancer distributes inbound flows that arrive at the load balancer's front end to backend pool instances. These flows are according to configured load-balancing rules and health probes. The backend pool instances can be Azure Virtual Machines or instances in a virtual machine scale set.
For more information : https://learn.microsoft.com/en-us/azure/load-balancer/load-balancer-overview

You can locate the load balancer resources from all resources, or from the global search. (IMAGE 23)
Image description

We will be using Azure basic load balancer, SKU, as the public load balancer for this project since we intend to serve websites from the virtual machines. For more information on Azure load balancer SKUs, see: https://learn.microsoft.com/en-us/azure/load-balancer/skus#skus

Image description (IMAGE 24)

We will add a public IP to the load balancer that will sit at the front of the availability set that has the virtual machines.
Image description (IMAGE 25)

Image description(IMAGE 26)

Next, we will add the virtual machines in the availability sets to the backend of the load-balancers.
Image description (IMAGE 27)

Image description (IMAGE 28)

Inbound RULE
Here we link the Frontend_IP_Configuration and Backend_Pool
Protocol: TCP, Port: 80 (to access the webserver content), BackendPort :80 (to the virtual machines)
Image description (IMAGE 29)

HEALTH PROBE: Will monitor the health status of the virtual machines in the backend. This will determine if traffic will still be directed to the virtual machines.
Image description (IMAGE 30)

After adding the inbound rules, we review and create
Image description (IMAGE 27)

Image description (IMAGE 28)

Checking the status of the virtual machines in the availability sets confirms that the load-balancers frontends IP configuration linked to the VM.
Image description (IMAGE 29)

Image description (IMAGE 30)

We confirm if the IP is still serving the default Apache web page.

Image description (Image 31)

Project completed; please leave your comments, feedback, and project suggestions for me to write about.

You can also read: How to add virtual machine to an existing availability-sets on Azure.

https://dev.to/cli_tayo/adding-a-virtual-machine-to-an-existing-availability-sets-on-azure-ahh

Top comments (0)