DevOps, Day - 41

LB2

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:

Read more here

  1. Application Load Balancer (ALB) - operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices.
  1. Network Load Balancer (NLB) - operates at layer 4 of the OSI model and is ideal for applications that require high throughput and low latency.
  1. Classic Load Balancer (CLB) - operates at layer 4 of the OSI model and is ideal for applications that require basic load balancing features.

Step 1: Launch EC2 Instances

  1. Log in to your AWS Management Console.

  2. Go to the EC2 dashboard.

  3. Click the "Launch Instance" button.

  4. Choose an Ubuntu AMI (Amazon Machine Image) as your instance type. You can search for "Ubuntu" in the "Quick Start" section.

  5. Select an instance type and configure the instance as needed (e.g., instance size, VPC, security groups). Make sure the instances have public IP addresses.

  6. On the "Additional Details" page, you can add User Data. User Data is a script that runs when the instance launches. Add the following User Data script to install Apache and modify the index.html file:

    For the first instance:

     #!/bin/bash
     apt update
     apt install -y apache2
     echo 'Your Name' > /var/www/html/index.html
     service apache2 restart
    

  7. Repeat Step 1 - Step 6 for the second instance, and paste the below script in the User Data section.

    For the second instance:

     #!/bin/bash
     apt update
     apt install -y apache2
     echo 'TrainWithShubham Community is Super Aweasome :)' > /var/www/html/index.html
     service apache2 restart
    

  8. Complete the instance creation process, and launch both instances.

Step 2: Access the EC2 Instances

  1. Once the instances are running, note down their public IP addresses from the EC2 dashboard.

  2. Edit inbound rules --> Enable port number 80 for both instances.

  3. Open a web browser and paste the public IP address of the first instance into the address bar. You should see a webpage displaying "Your Name."

  4. Similarly, paste the public IP address of the second instance into the address bar, and you should see a webpage displaying "TrainWithShubham Community is Super Awesome :)."

You've now successfully launched two EC2 instances with Ubuntu AMIs, installed the Apache Web Server, and modified the index.html files to display the desired content. You can access both instances using their public IP addresses.


Step 1: Create a Target Group

  1. Target groups define how the ALB routes traffic to your instances.

    • Configure the target group as follows:

    • In the "Target type" section, select "Instance."

    • Give the target group a name.

    • Set the "Port" to 80 (or the port your instances are serving traffic on).

    • Select the same VPC as your instances.

    • Set the protocol to HTTP (or the protocol your instances are using).

    • Review the settings and click "Next"

    • Click on Create target group.

    • Our target group is created


Step 2: Create an Application Load Balancer

  1. After creating the target group, go to the EC2 dashboard --> Click the "Load Balancers" section.

  2. Configure the load balancer as follows:

    • Give your ALB a name.

    • Select the same VPC that your EC2 instances are in.

    • Select two or more availability zones.

    • For "Listeners," leave the default HTTP (80).

    • Under "Configure routing," select "Existing target group" and choose the target group you created in Step 1.

    • Configure security settings and other options as needed.

    • Review the settings, and click "Create" to create the ALB.


Step 3: Register Instances with the Target Group

  1. After creating the target group, click on it to view its details.

  2. In the "Targets" tab, click "Edit" to register instances.

  3. You will see a list of available instances. Select the instances you want to add to the target group, which should be the EC2 instances you launched in Task 1. Click "Add to registered."

Step 4: Test the ALB

  1. Once the instances are registered with the target group, go back to the "Load Balancers" section, and select your ALB.

  2. In the "Description" tab, you can find the DNS name of your ALB (e.g., my-alb-1234567890.us-east-1.elb.amazonaws.com).

  3. Open a web browser and access the ALB's DNS name. You should see the content served by your EC2 instances. The ALB will distribute traffic between the registered instances.

Step 5: Verify Target Health

  1. In the "Target Groups" section, click on your target group to see the list of registered instances.

  2. In the "Targets" tab, you can monitor the health status of the instances. Make sure they show a healthy status, indicating that the ALB is correctly routing traffic to them.

By following these steps, you have successfully created an Application Load Balancer (ALB), added your EC2 instances as target groups, and tested the ALB's load balancing capabilities.


Thank you so much for reading

Follow me on LinkedIn to see interesting posts like this : )

Linkedin

10
Subscribe to my newsletter

Read articles from Vrishni Shree V B directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vrishni Shree V B
Vrishni Shree V B

๐Ÿ’ป Python | Docker | Jenkins | Networking | Git | Linux ๐Ÿ’ป Passionate about leveraging technology to drive efficiency and deliver innovative solutions. Proficient in Python development, Docker containerization, Jenkins automation, computer networking, Git version control, and Linux administration. Skilled in collaborating with diverse teams to deliver high-quality software products. Proficient in AWS EC2 instance management and deployment. Seeking new opportunities to apply my expertise and contribute to impactful projects. Let's connect and explore how we can work together! Inter-personal Skills: Communication, Adaptability, Emotional intelligence, Active listening, Collaboration. Happy To Connect๐Ÿ”—๐Ÿ˜Š Feel free to reach me out๐Ÿ˜ƒ@ --> vrishnishreevb531@gmail.com ๐Ÿ“ฌ