Edit Template

Mastering Elastic Load Balancing: A Complete Guide

Introduction

Elastic Load Balancing (ELB) is offered by cloud platforms like Amazon Web Services (AWS) which helps in the efficient distribution of incoming traffic across multiple servers at the same time Ensuring smooth operation of various processes. ELB increases both availability and scalability of applications by optimizing responses to infrastructure requests. Moreover, it dynamically adapts to the variations in traffic load to ensure maximum resource utilization as well as high availability of applications.

Why is Load Balancing Important?

Load balancing is fundamental in modern cloud architectures. Here are the key reasons why:

  1. High Availability: Traffic overloads any single server so distributing would mean minimization of downtime thus continuous availability.
  2. Scalability: ELB can automatically scale based on the traffic spike which is extremely important for applications seeing sudden and fluctuating workloads.
  3. Fault Tolerance: ELB avoids routing traffic topped instances preventing users from being affected by server failures.
  4. Improved Performance: By load balancing available servers, optimization resource usage becomes possible thus reduction in application latency and quicker responsiveness.

Types of Elastic Load Balancers

AWS provides several types of Elastic Load Balancers, each suited for specific use cases:

  1. Application Load Balancer (ALB):
    • Operates at the application layer (Layer 7 of the OSI model).
    • Ideal for HTTP and HTTPS traffic.
    • Supports advanced routing features such as path-based and host-based routing.
    • Suitable for microservices and containerized applications.
  2. Network Load Balancer (NLB):
    • Operates at the transport layer (Layer 4 of the OSI model).
    • Handles TCP, UDP, and TLS traffic.
    • Offers ultra-low latency and high throughput.
    • Best for scenarios requiring extreme performance and static IP addresses.
  3. Classic Load Balancer (CLB):
    • Operates at both the application and transport layers (Layer 7 and Layer 4).
    • Supports basic load balancing for legacy applications.
    • Gradually being replaced by ALB and NLB.
  4. Gateway Load Balancer (GWLB):
    • Facilitates seamless deployment of virtual appliances like firewalls and intrusion detection systems.
    • Operates at Layer 3, providing a transparent gateway for traffic inspection and forwarding.

Step-by-step procedure for creating an Elastic Load Balancer

Step 1: Launching the First EC2 Instance

  1. Navigate to EC2 by clicking on the Services menu in the top, then click on EC2 in the Compute section.
  2. Navigate to Instances on the left panel and click on Launch Instances button.
  3. Name: Instance 1
  4. Select the AMI as Amazon Linux Image 2 and click the select button.

5. Select the instance type as t2.micro and Create a new key pair with the name as key1.

6. Under Network Settings, leave VPC, Subnet with default settings, enable Auto-assign public IP.
7. Click on Create a new Security Group with name SG-1, description with Security group to allow traffic to EC2.

8. Check Allow SSH from and Select Anywhere from dropdown

  • To add SSH,
    • Choose Type: SSH
    • Source: Select Anywhere
  • For HTTP, Click on Add security group rule
    • Choose Type: HTTP
    • Source:  Select Anywhere
  • For HTTPS, Click on Add security group rule
    • Choose Type: HTTPs
    • Source:  Select Anywhere

9. Click on Advanced details and under the User data: section, Enter the following script to create an HTML page served by an Apache httpd web server.
#!/bin/bash
sudo su   
yum update -y
yum install httpd -y
echo “<html><h1> Welcome to Server 1 </h1><html>” > /var/www/html/index.html              
systemctl start httpd   
systemctl enable httpd
10. Keep Rest thing Default and Click on Launch Instance Button.
11. Select View all Instances to View Instance you Created.
12. Launch Status: Your instance is now launching, Click on the instance ID and wait for complete initialization of the instance till status changes to Running.


Step2: Launching the Second Instance

Follow the above steps to create the second instance and In the advanced settings of EC2, paste the below command.
#!/bin/bash
sudo su   
yum update -y
yum install httpd -y
echo “<html><h1> Welcome to Server 2 </h1><html>” > /var/www/html/index.html              
systemctl start httpd   
systemctl enable httpd

Step3: Create Target Group and Load Balancer

  1. In the EC2 Console, Navigate to Target Groups, present in the left panel under Load Balancing.
  2. Click on the Create target group button.
  3. Choose the target type as Instance, Target Group Name as MyTarget-Group.
  4. Keep all the settings as default.
  5. Scroll to the end of the page and click on the Next button.
  6. For Step 2, Register targets
    1. Select both instances and click on the Include as pending below button.

Step4: Create Load Balancer

  1. Click on create Load Balancer on the left corner of EC2 Console.
  2. Select Load Balancer Type: Under the Application load balancer, click on Create button.
  3. To create an Application load balancer, configuring the load balancer as below
  • For the Basic configuration section,
    • Name: Enter MyLoadBalancer
    • Scheme: Select Internet-facing
    • IP address type: Choose IPv4

4. For the Network mapping section:

  1. VPC: Select Default
  2. Mappings: Select all the Availability zone present

5. For the Security groups section,Select the SG-1 Security group from the dropdown and remove the default security group.
6. For the Listeners and routing section, the listener is already present with Protocol HTTP and Port 80 and Select the target group MyTargetGroup for the Default action forwards to option.


7. Keep the tags as default and click on the Create load balancer button. 

Step5: Testing the Load Balancer

  1. Click on Target groups from the left menu section.
  2. Select MyTargetGroup and navigate to the Targets tab below.
  3. Wait until the status column of the instances changes to healthy (this means both web servers have passed ELB health check)

4. Next, navigate to Load Balancers and notice the state of ELB is active.
5. Copy the DNS name of the ELB and enter the address in the browser.


6. You should see the index.html page content of Web Server 1 or Web Server 2 .

7. Now Refresh the page a few times. You will observe that the index pages change each time you refresh.
8. Note: The ELB is equally dividing the incoming traffic to both servers in a Round Robin manner.

Benefits of Elastic Load Balancing

  1. Automatic Scaling:
    • ELB dynamically adjusts capacity to handle varying levels of application traffic without manual intervention.
  2. Security Integration:
    • Supports integration with AWS Web Application Firewall (WAF) to protect against malicious traffic.
    • Offers SSL/TLS termination to encrypt data between clients and the load balancer.
  3. Monitoring and Logging:
    • Provides detailed metrics via Amazon CloudWatch.
    • Logs can be stored in Amazon S3 for compliance and troubleshooting.
  4. Global Accessibility:
    • With multi-AZ deployments, ELB ensures traffic is routed to the nearest healthy target in any region.

Use Cases of Elastic Load Balancing

  1. E-Commerce Platforms:
    • E-commerce applications have unpredictable traffic patterns, especially with seasonal sales spikes and event specific sales.
    • Shopping is done seamlessly with the help of microservices where ELB guarantees uninterrupted access to all servers.
  2. Microservices Architectures:
    • Application Load Balancers are ideal for directing requests to containerized services using HTTP headers or query parameters.
  3. High-Performance Applications:
    • Network Load Balancers are preferred due to their ultra-low latency for real time voice, video and financial trading systems.
  4. Enterprise Applications:
    • Guarantees business class dependability along with unparalleled protection against malicious attacks towards important applications and data.

Conclusion

Elastic Load Balancing is crucial for any application that needs modern scaling and building and multi-purpose resilience. Not only does ELB ensure effective traffic management by routing it to available servers, but also offers enhanced uptime and performance capabilities for fragmented systems. As more business workloads migrate to the cloud, the value and need of mastering Elastic Load Balancing resources grows for cloud engineers and architects. From microservices and real-time data streams to enterprise applications, ELB provides services to all. Follow DevOps Horizon for more blogs on Cloud and DevOps.

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Most Recent Posts

    Category

    content created for you!

    Company

    About Us

    FAQs

    Contact Us

    Terms & Conditions

    Features

    Copyright Notice

    Mailing List

    Social Media Links

    Help Center

    Products

    Sitemap

    New Releases

    Best Sellers

    Newsletter

    Help

    Copyright

    Mailing List

    © 2023 DevOps Horizon