Day 41: Setting up an Application Load Balancer with AWS EC2 ๐Ÿš€

Day 41: Setting up an Application Load Balancer with AWS EC2 ๐Ÿš€

ยท

5 min read

This is #90DaysofDevopschallenge under the guidance of Shubham Londhe sir.

Introduction

Welcome back to another exciting installment of our DevOps journey. In our previous sessions, we delved into the intricacies of EC2 instances and launch templates. Today, we're venturing into the realm of load balancing, a crucial component in the architecture of scalable and high-performing applications.

Understanding Load Balancing

Load balancing is the art of efficiently distributing incoming network traffic across multiple servers or resources. This practice ensures optimal resource utilization, enhances reliability, and boosts the performance of applications, especially in large-scale environments.

Elastic Load Balancing (ELB)

Enter Elastic Load Balancing (ELB), a vital service offered by Amazon Web Services (AWS). ELB automatically spreads incoming traffic across a fleet of EC2 instances, ensuring seamless operation and fault tolerance. AWS provides three main types of load balancers:

  • Application Load Balancer (ALB): Operates at layer 7 of the OSI model, making it ideal for applications requiring advanced routing and microservices architecture.

  • Network Load Balancer (NLB): Works at layer 4 of the OSI model, catering to applications demanding high throughput and minimal latency.

  • Classic Load Balancer (CLB): Functions at layer 4 and is suited for basic load balancing needs.

๐ŸŽฏ Today's Tasks:

Let's roll up our sleeves and dive into the practical aspects of setting up an Application Load Balancer (ALB) with AWS EC2.

Task 1: Setting Up EC2 Instances

  1. Launch EC2 Instances:

    • Go to the AWS Management Console and navigate to the EC2 dashboard.

    • Click on "Launch Instance" and choose an Ubuntu AMI.

    • In the "Advanced Details" section of the instance configuration, add User Data to install the Apache Web Server during instance launch.

        #!/bin/bash
      
        # Update the package repositories and installed packages
        sudo apt update -y
      
        # Install Apache Web Server
        sudo apt install apache2 -y
      
        # Start Apache service
        sudo systemctl start apache2
      
        # Enable Apache to start on boot
        sudo systemctl enable apache2
      
  2. Customize index.html:

    • Once the instances are launched and running, SSH into each instance.

    • Use the command echo "<html><body><h1>Your Name Here</h1></body></html>" | sudo tee /var/www/html/index.html to modify the index.html file on the first instance, replacing "Your Name Here" with your actual name.

    • Repeat the same process for the second instance, but this time modify the index.html file to include the message "TrainWithShubham Community is Super Awesome :)".

        # Modify the index.html file to include your name
        echo "<html><body><h1>Akash Dhengale</h1></body></html>" | sudo tee /var/www/html/index.html
      
        # Modify the index.html file to include a customized message
        echo "<html><body><h1>TrainWithShubham Community is Super Awesome :)</h1></body></html>" | sudo tee /var/www/html/index.html
      
  3. Retrieve Public IP:

    • In the EC2 dashboard, locate your instances and copy the public IP addresses of both EC2 instances.

  4. Test Apache Server:

    • Open a web browser and paste the public IP address of the first EC2 instance into the address bar. You should see a webpage displaying your name.

    • Repeat the process with the public IP address of the second EC2 instance to ensure the customized message is displayed.

Task 2: Configuring Application Load Balancer (ALB)

  1. Create ALB:

    • In the AWS Management Console, navigate to the EC2 dashboard.

    • Click on "Load Balancers" and choose "Create Load Balancer."

    • Select "Application Load Balancer (ALB)" and configure it with appropriate settings, including listeners, availability zones, and security settings.

  2. Add EC2 Instances to Target Groups:

    • In the ALB configuration, create a target group and add the EC2 instances launched in Task 1 as target members.

    • Configure health checks to ensure the ALB can detect healthy instances.

  3. Verify ALB Functionality:

    • Once the ALB is created and configured, check the health status of the target instances in the target group.

  1. Configure Security Group for ALB:
  • After creating the ALB, navigate to the security tab and click on Edit.

  • Select Create a new security group specifically for the load balancer and provide a descriptive name and description.

  • Add an inbound rule to allow traffic on port 80 (HTTP), then click on Create Security Group to save the settings.

  • Apply the custom security group settings to your ALB by selecting the created security group and clicking Save Changes.

  • Conduct tests by accessing the ALB's DNS name in a web browser and observing how traffic is distributed across the EC2 instances.

Conclusion

Congratulations on embarking on this journey to set up an Application Load Balancer with AWS EC2! By mastering load balancing techniques, you're equipping yourself with essential skills to build resilient and scalable applications in the cloud.

Stay tuned for more thrilling adventures in the world of DevOps! Keep experimenting, keep learning, and never hesitate to explore the vast horizons of technology.

๐Ÿ’ก
If you have any questions or need help, feel free to ask in the comments section! ๐Ÿค” I would be happy to answer them!
๐Ÿ’ก
If you found the content helpful, please consider giving it a thumbs up ๐Ÿ‘ and following for more useful information. Your support is greatly appreciated!

Thanks for taking the time to read! ๐Ÿ’œ

Did you find this article valuable?

Support Akash Dhengale by becoming a sponsor. Any amount is appreciated!

ย