Thursday, April 30, 2020

Configure Public load balancer

9:28 AM Posted by Dilli Raj Maharjan , No comments

Load balancing refers to the process of distributing a set of tasks over a set of resources, with the aim of making their overall processing more efficient. It provides fault tolerance, high availability, stability and Naming abstraction. Load balancing techniques can reduce the response time  avoiding unevenly overloading compute nodes while other compute nodes are left idle. Load balancer offers a public IP address to front-end internet traffic within a single availability domain, or across multiple availability domains. OCI load balancer sits between the clients and the backend servers.

The core task of load balancer are:

Service Discovery: Discover which backend servers are available to serve the client request. 
Health Check: Periodically check the health of backend server.
Algorithm: Use specified algorithm to balance individual requests across the healthy backend servers. Available algorithms are Round Robin, IP hash, Least connections.

Following are the steps to create public load balancer to server web request to client. There are two backend web servers and Round Robin algorithm has been used to balance the web servers request.


Create Virtual Cloud Networks to place Load balancer. Click on Navigation Menu > Networking > Virtual Cloud Networks.



Click on Create VCN to create new VCN.


Provide VCN Name. Select the appropriate compartment. Provide the CIDR Block and click on Create VCN. I have chosen 192.168.0.0/22 CIDR which means there will be four /24 subnets: 192.168.0.0/24, 192.168.1.0/24, 192.168.2.0/24 and 192.168.3.0/24



Once VCN is created the status of VCN become AVAILABLE. Click on Create Subnet to create subnets.


Provide Subnet Name. Make sure you create Regional Subnet type for the subnet for Load balancer. Provide CIDR block.  I have provided 192.168.0.0/24 CIDR block for Subnet LB_Subnet.  Provide Route table as Default Route table for LB_VCN and Make sure you select Public Subnet.



Select Default Security List for LB_VCN as Security list for the Subnet and click on Create Subnet.



Similar create different subnets for Web servers. Provide Subnet name and Subnet Type. In this case I have selected Availability Domain-specific subnet. Select appropriate Availability Domain. Select CIDR block. Select Default Route Table for LB_VCN as Route table and Public Subnet as the subnet access.



Select Default Security List for LB_VCN as the security list and click on Create Subnet.



Similarly I have create another Subnet web2_subnet in second Availability Domain with CIDR block 192.168.2.0/24.



Create Internet gateway to access compartments and web from anywhere.


Add Route Rules in Default Route Table for LB_VCN to redirect all the internet request via Internet gateway LB_IGW.



Once the route rule is added it looks something like below.



Add stateful ingress rule to allow all traffic to TCP port 80 in Default Security List. Here Source CIDR is 0.0.0.0/0 means anywhere from internet, Protocol selected is TCP and Destination Port is 80. Click on Add Ingress Rules to allow traffic.



I have create two compute instance with Oracle linux 7.6 as Operating System. All required redhat packages for http has been installed and configured. Web1 is first compute instance hosted in AD-1 and Web2 is second compute instance hosted in AD-2. These servers are ready to serve web requests.



I can access web1 and web2 webpages. Accessing web1 using public IP address of web1.



Accessing web2 with public IP address of web2.

Create load balancer. 

Click on Navigation menu > Networking > Load Balancer.



Click on Create Load Balancer.


Provide Load Balancer name, name can be anything. Choose visibility type, since we are pacing web servers as backend severs for the load balancer choose Public. Choose total bandwidth type, we are expecting moderate amount of traffic so I have selected small. Select VCN name we have created earlier, LB_VCN is the VCN we have created. Choose subnet we have created LB_Subnet as regional subnet for Load balancer.



On the left of the create Load balancer page There is link to Choose Backends. Click on Choose Backends.



Click on Add Backends button to add backend servers.



Select all required backend servers. In my case I have selected Web1 and Web2 as my backends.




Select the Health check policy. Select TCP as protocol. Port as 80.



Once again click on Configure Listener at the left of the window. Provide listener Name, Traffic that listener should handle, select HTTP as listener traffic type and 80 ingress traffic port. Click on Show Advanced options.



Click on Security list to view security lists




Make sure Automatically add security list Rules is selected. Click on Session Persistence to modify Session persistence option.




In my case I do not need session persistence option so I have selected Disable Session Persistence option. If you need session persistence option select appropriate option.




Finally click on Submit to create Load balancer.



Now get public IP address of load balancer and access web.





Now I have accessed web using the public IP address of load balancer. For the first time my request is being server by first web server web1.



I clicked on refresh and my request is now served by second web servers.



It took lit bit longer to update overall Health status. It took around 30 min to update and show status to OK.