Welcome to Day 41 of the #90DaysOfDevOps Challenge. In today's session, we will explore the concept of load balancing and focus on setting up an Application Load Balancer (ALB) with AWS EC2. Load balancing is a critical component in distributed systems that helps distribute incoming network traffic across multiple resources, improving performance, scalability, and fault tolerance.
What is Load Balancing?
Load balancing is a crucial technique used in modern IT infrastructures to efficiently distribute incoming network traffic across multiple servers or instances. The primary goal of load balancing is to ensure optimal resource utilization and prevent overload on a single server. By evenly distributing the traffic, load balancing improves the overall performance and responsiveness of applications, leading to a better user experience.
Load balancing also adds redundancy and high availability to the system. In case one server or instance becomes unavailable or experiences a surge in traffic, the load balancer can intelligently route the requests to the available servers. This helps to maintain the availability of the application and prevent disruptions caused by server failures.
Elastic Load Balancing
Elastic Load Balancing (ELB) is an AWS service designed to automatically distribute incoming application traffic across multiple targets within an Amazon Web Services (AWS) environment. It offers three types of load balancers to suit different application architectures:
Application Load Balancer (ALB)
ALB operates at the application layer (Layer 7) of the OSI model and is ideal for distributing traffic to multiple services or containers based on specific routing rules. It supports advanced features such as path-based routing, host-based routing, and content-based routing, enabling flexible and granular traffic management.
Network Load Balancer (NLB)
NLB operates at the transport layer (Layer 4) of the OSI model and is optimized for handling high volumes of traffic. It is capable of handling millions of requests per second with ultra-low latency. NLB is commonly used for TCP and UDP-based workloads that require extreme scalability and high performance.
Classic Load Balancer (CLB)
CLB is the legacy load balancer provided by AWS. It operates at both the application and transport layers and offers basic load-balancing capabilities. While ALB and NLB provide more advanced features and better performance, CLB can still be suitable for simple applications or those that require backward compatibility.
With Elastic Load Balancing, you can easily set up, configure, and manage load balancers to distribute traffic across your application instances. The load balancer automatically scales and adapts to changing traffic patterns, ensuring optimal performance and fault tolerance. Additionally, ELB integrates seamlessly with other AWS services, such as Auto Scaling, to provide a robust and scalable infrastructure for your applications.
Task 1 - Launching EC2 Instances and Installing Apache Web Server
Log in to the AWS Management Console and navigate to the EC2 service.
Click on "Launch Instance" to start the instance creation process.
Choose the Ubuntu AMI as the base image for your instances.
Select the desired instance type and configure other instance details as needed.
Continue through the remaining steps, configuring storage, security groups, and other settings as desired.
Scroll down to the "Advanced Details" section.
Enter the following script in the "User Data" field to install the Apache Web Server:
#!/bin/bash sudo apt update sudo apt install -y apache2 sudo systemctl start apache2 sudo systemctl enable apache2
Launch the instances and wait for them to become running.
Do the same for the second instance
Connect to the instances and modify the index.html file located in the Apache document root (/var/www/html).
Replace the default content with your name and something else to differentiate instance 1 and instance 2.
Save the file.
Once the instances are running, navigate to the EC2 dashboard and locate the public IP addresses of the instances.
Open a web browser and enter the first instance's public IP address. You should see the Apache default page.
Task 2 - Creating an Application Load Balancer (ALB)
In the AWS Management Console, navigate to the EC2 service.
Click on "Load Balancers" in the left navigation pane and then click on "Create Load Balancer."
Choose "Application Load Balancer" as the load balancer type and click "Create."
Configure the ALB with a unique name, listener configuration, and select the appropriate VPC.
Specify the Availability Zones where the ALB should distribute traffic.
Set up the security groups to allow incoming traffic to the ALB.
In the "Configure Routing" section, create a new target group and specify the instances launched in Task 1 as targets.
Configure health checks to monitor the status of the instances.
Complete the ALB creation process and wait for it to become active.
Once the ALB is active, test its functionality by accessing the ALB's DNS name in a web browser.
Verify that the traffic is being distributed to the instances and that the modified content is displayed.
You have successfully launched EC2 instances, installed the Apache Web Server, and created an Application Load Balancer (ALB) to distribute traffic to the instances.
Congratulations on completing Day 41. By setting up an Application Load Balancer with AWS EC2, you have taken a significant step towards building scalable and highly available applications. Stay tuned for more exciting AWS content in the upcoming days.
Did you find this article valuable?
Support Esteban Moreno by becoming a sponsor. Any amount is appreciated!