DevOps(Day-41) : Setting up an Application Load Balancer with AWS EC2 ๐ โ
TABLE OF CONTENTS
What is Load Balancing?
Load balancing is the utility which provides application stability in a project. As the load on an application, increases let's say due to the engagement of 100s or 1000s of users instantly, a server might fail to take the sudden increase in load. In this case, Load Balancing helps to distribute the network traffic between multiple servers. So that if one server goes down another one is up or both can be up with a fixed and limited distributed amount of load.
Load balancing performs these critical tasks:
It manages the sudden increase in traffic and prevents it in a single server.
Provides quick response to the application when the user is on the app.
Ensures performance and reliability of computing resources, both physical and virtual.
Adds redundancy and resilience to computing environments.
Elastic Load Balancing (ELB)
It 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) - It makes routing decisions at the application layer (HTTP/HTTPS). It operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices.
Network Load Balancer (NLB) - Network Load Balancer makes routing decisions at the transport layer (TCP/SSL). It operates at layer 4 of the OSI model and is ideal for applications that require high throughput and low latency.
Classic Load Balancer (CLB) - It operates at layer 4 of the OSI model and is ideal for applications that require basic load-balancing features.
Task 1: Spin up two Apache web servers
launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.
Check in the server if Apache is installed using the systemctl command.
- Navigate to /var/www/https/index.html file to view the content of the Apache web server.
As per the task, 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 Awsome :) ".
Below is for server 1.
- Below is for server 2, apache web server config changes.
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.
Task 2: Create an Application Load Balancer
Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.
- Navigate to open the below Load Balancer form and provide a LB name.
- Select the subnets you want your application to be run on.
- As this is an Application Load Balancer so the traffic routing is based on HTTP/HTTPS layer. So, select a suitable HTTP or HTTPS where you want your application to be run.
- Create a target group which plays a vital role in ALB.
- Include the Servers that you have spun up for Apache web server in above task.
- Review and create the load balancer now.
You can check now EC2 instances which you launch in task-1 to the ALB as target groups will be visible in LB.
Verify that the ALB is working properly by checking the health status of the target instances and testing the load-balancing capabilities.
Navigate to the LB URL and check the two Apache web server websites. They will be displayed as from server 1 and server 2 and the traffic is evenly distributed among them.
We have seen how Load Balancer plays an important role in the production environment for any application.
Thanks for reading my article. Have a nice day.
WRITTEN BY Biswaraj Sahoo --AWS Community Builder | DevOps Engineer | Docker | Linux | Jenkins | AWS | Git | Terraform | Docker | kubernetes
Empowering communities via open source and education. Connect with me over linktree: linktr.ee/biswaraj333