Setting-Up A Basic Azure Load Balancer & Availability Sets
Tags: azure, cloudskills, servers
Published: 2022-09-24 10:26:52

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


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2axr2ejd4jouwpa1mfip.png)




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.)
[](https://azure.microsoft.com/en-us/free/)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9iwrrdjarasn00hhudrr.png)

**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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kzptlmhkzao5kdctag8r.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kh0vpegeozvailmaqizd.png) **(IMAGE 2)**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnxeztq8gk44el0zpdm1.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bp75qzzb316muxlxs4o.png) **(IMAGE 4)**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i6ppn1l75403snvl8j3o.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d31ajvolg7k4e3hd5daz.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c45lto2lkjiee2wvzewo.png)**(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/omqmag94ce73zks0i7gb.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l467vr9dbatygp4hd93o.png)**(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/16lgvifdukuynp8mdc8e.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f9qwmv05ldw7pokcrkq6.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vi82pldyk02k9osngt77.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gho2t5nz6p5vqgtegjce.png) **(IMAGE 12)**

In the custom data box input this bash script. :

```
#!/bin/sh
sudo apt install apache2 -y
```
After the setup has been validated, create the VM. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m02xttrczx6keozehigi.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hkmsayq8k28cvoppzt4i.png) (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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/186ptsvf3ogvankul496.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62pofj3udlhq3bzmh62g.png) **(IMAGE 15)**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lub8z67yi3ip6pxup1a.png) **(IMAGE 16)**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/36lngvstygp6v06xxjjr.png) **(IMAGE 17)**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uiuuch3oc7ngb0nh22d0.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jkevnquv0cu98928uiii.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8aece7w49dbiq1v9ytcb.png) **(IMAGE 20)** (We will disable the public IP from setup wizard this time) 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5bjdvtqw1oidawnnfo2.png)**(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bwd07ee3s0848vez1xrr.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ubsjwc4rsgi3bkeyaawc.png) 

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6m5a4e2c4weok1ewkwo.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vp6svqp8nuwwguyyp58s.png) **(IMAGE 25)**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c65vui5rugry9fxx8dnq.png)**(IMAGE 26)**

Next, we will add the virtual machines in the availability sets to the backend of the load-balancers.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iy0g4qvd1mte23y1yeci.png) **(IMAGE 27)**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jft8r1p6l6jlk5x4vn8k.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z3d3rdnupaobz01vxm29.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjyw2bqm9ogbuwsl0sfk.png) **(IMAGE 30)**

After adding the inbound rules, we review and create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0soepcqf26lropxjojg7.png) **(IMAGE 27)**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/neyilxy4n8q5myit6e0g.png) **(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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pg397xu3tfwz60gu32oi.png) **(IMAGE 29)**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f8534hvuv93mcorbndci.png) **(IMAGE 30)**

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/08qkd5ipbko7kez7r3ho.png) **(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