Day 41 - Setting up an Application Load Balancer with AWS EC2 ๐Ÿš€ โ˜

Day 41 - Setting up an Application Load Balancer with AWS EC2 ๐Ÿš€ โ˜

ยท

3 min read

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:

1. Application Load Balancer (ALB) - operates at layer 7 of the OSI model and is ideal for applications that require advanced routing and microservices.

2. 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.

Task 1:

Launch 2 EC2 instances with an Ubuntu AMI and use User Data to install the Apache Web Server.

  1. Login to AWS Console and navigate to the EC2 service.

  2. Click on "Launch Instances" and create 2 Ubuntu instances.

  3. Choose Amazon Machine Image (AMI)" as Ubuntu Server 20.04 and t2micro

  4. Select the instance type as t2micro and provide the keypair value

  5. In the Network settings, Configure the storage section to provide your VPC and security groups or leave it to the default.

  6. Under Advanced details > User data, write a script to install Apache server

     #!/bin/bash
     sudo apt-get update 
     sudo apt-get install -y apache2
     sudo systemctl start apache2
     sudo systemctl start apache2
    

    Click on "Launch Instances" to launch the instance.

  7. Two Ubuntu instances will be created

  8. Now connect to the instances to check if the Apache webserver is running

     sudo systemctl status apache2
    

    Now we will edit the index.html file of Apache server

  9.   cd /var/www/html
      vi index.html
      <body>
                  <p> Hi everyone this is Rajendra Apache pagde </p>
      </body>
    
  10. Let's access the Apache webserver with Instance publicIP:80

    In this way, we can install any application from user data while launching an instance.


Task 2:

Create an Application Load Balancer (ALB) in EC2 using the AWS Management Console.

  1. Login to AWS console and navigate to load balancers > Create load balancer

  2. Select the load balancer type as an Application load balancer

  1. Configure the load balancer such as name, scheme, IP address type, listeners, security group, and availability zones. For the listener, you can choose HTTP or HTTPS, depending on your application's requirements.

    Under Network mapping configure the VPC and mapping zones all

    1. For listeners and routing we need to specify the target group, since we don't have any we need to create one here. So click on Create target group and the target type will be the instance.

    2. Provide the name of the target group and click on Next

    3. You will be able to see the running instances, here select an instance for which you wanted to register targets as LB.

    4. Now click on create target group

    5. To fix the Access issue detected apply all the 3 zones in subnet

    6. Now get back to Listeners and routing and apply the target group

    7. Click on Create Load balancer

    8. Now test your Load Balancer. Copy the DNS name from Load balancer Description and paste in a new browser tab.

ย