What is Load Balancing?
Load balancing is the distribution of workloads across multiple servers to ensure consistent and optimal resource utilization. It is an essential aspect of any large-scale and scalable computing system, as it helps you to improve the reliability and performance of your applications.
Elastic Load Balancing:
Elastic Load Balancing (ELB) is a service provided by Amazon Web Services (AWS) that automatically distributes incoming traffic across multiple EC2 instances. ELB provides three types of load balancers:
Application Load Balancer (ALB) - operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices. After the load balancer receives a request, it evaluates the listener rules in priority order to determine which rule to apply and then selects a target from the target group for the rule action. You can configure listener rules to route requests to different target groups based on the content of the application traffic. Routing is performed independently for each target group, even when a target is registered with multiple target groups. You can configure the routing algorithm used at the target group level. The default routing algorithm is round robin; alternatively, you can specify the least outstanding requests routing algorithm.
Network Load Balancer (NLB) - functions at layer 4 of the Open Systems Interconnection (OSI) model and is ideal for applications that require high throughput and low latency. It can handle millions of requests per second. After the load balancer receives a connection request, it selects a target from the target group for the default rule. It attempts to open a TCP connection to the selected target on the port specified in the listener configuration.
Gateway Load Balancer (GWLB) - operates at layer 3 of the Open Systems Interconnection (OSI) model, the network layer. It listens for all IP packets across all ports and forwards traffic to the target group that's specified in the listener rule. It maintains the stickiness of flows to a specific target appliance using a 5-tuple (for TCP/UDP flows) or 3-tuple (for non-TCP/UDP flows). The Gateway Load Balancer and its registered virtual appliance instances exchange application traffic using the GENEVE protocol on port 6081.
**Classic Load Balancer (CLB) - operates at layer 4 of the OSI model and is ideal for applications that require basic load balancing features.\**
[Note: Classic Load Balancer already got retired on 15 August 2022 and it is only available in VPCs.] more info
Task 1:
Launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.
Modify the index.html file to include your name so that when your Apache server is hosted, it will display your name also do it for 2nd instance which includes " TrainWithShubham Community is Super Awesome :) ".
Copy the public IP address of your EC2 instances.
Open a web browser and paste the public IP address into the address bar.
You should see a webpage displaying information about your PHP installation.
Step 1: Launch two instances with the AMI "ubuntu" and provide all mandatory details necessary for the proper functioning of the Apache server
.
Step 2: We will use "user data" to automatically install the Apache server
in our instance.
Thus we get our instances launched successfully.
Check whether the apache server is properly installed or not.
Step 3: Now we modify the index.html file in this way.
Step 4: Paste the public IP addresses of our instances into the address bar. We should be able to see a webpage that displays information about our PHP installation in this way.
Task 2:
Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.
Add EC2 instances which you launch in task-1 to the ALB as target groups.
Verify that the ALB is working properly by checking the health status of the target instances and testing the load-balancing capabilities.
Step 1: First create a Target group,
select the instances, give a name to the "target group"
Step 2: Click on next
& include the running instances as pending below. Then click on create Target group.
Our Target group is now ready and it is not associated with load balancer yet.
Step 3: Select the load balancer
in EC2 service on the left side panel. Click on create load balancer and here we can get to see this page.
Step 4: Select application lb to create and fill info as seen below.
It's important to note that within a particular region, we can select the number of availability zones based on our specific needs.
Here, we have attached the target group "TG-1" to our App-LB.
Thus we create the application lb "App-LB" and it's active.
Step 5: Now click on the target group TG-1
and we can check the health status of target instances as well.
Step 6: Now, we will check if the server is working properly or not via the Application Load Balancer. To do this, simply copy the DNS name
.
Paste it over the address bar and ta-da the server is working.
We know that the application load balancer algorithm works in a round-robin
fashion right? Try to refresh the page it will show the next instance home page also. So the real magic of the application load balancer is seen via DNS name
i.e. we can see the target instances' homepage in a round-robin manner.
Hope this article helps you.
References
Thanks for reading my articles.
Happy learning and keep upskilling.
Peace out!!