Network load Balancer

Clinton Ogechi - Sep 2 - - Dev Community

A Network Load Balancer (NLB) is a type of load balancer provided by AWS that operates at the Transport Layer (Layer 4) of the OSI model. It is designed to handle high volumes of traffic and distribute it efficiently across multiple targets, such as EC2 instances, containers, or IP addresses.

Aim

Provide step-by-step instructions for creating a launch template, setting up an Auto Scaling Group, configuring the NLB, and verifying the setup to ensure that the traffic is balanced effectively.

Objective

  • Create and configure a launch template that automates the setup of EC2 instances.
  • Establish an ASG that dynamically adjusts the number of instances based on load requirements.
  • Set up a NLB and associate it with an ASG to distribute incoming traffic across multiple instances.
  • Verify the proper configuration of the NLB and Auto Scaling Group, ensuring that traffic is routed efficiently and that the system scales as needed.

Steps

1. Create a Launch Template

  • In the navigation pane, choose "Launch Templates".
  • Choose "Create launch template".
  • Enter a name and description for your launch template (e.g., MyLaunchTemplate ).
  • Choose an AMI (e.g., Amazon Linux 2 AMI).
  • Select an instance type (e.g., t2.micro ).
  • In the Advanced details section, under User data , paste your Bash script:
#!/bin/bash
yum update -y
yum upgrade -y
yum install httpd -y
systemctl start httpd
systemctl enable httpd
echo "this is my $(hostname)" > /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode
  • Choose a key pair and configure other settings like security groups.
  • Choose "Create launch template".

Image description

Image description

Image description

Image description

2. Create an Auto Scaling Group

  • In the navigation pane, choose "Auto Scaling Groups".
  • Choose "Create Auto Scaling group".
  • Enter a name for your auto-scaling group (e.g., MyAutoScalingGroup ).
  • Select the launch template created in step 1.
  • Choose "Next".
  • Choose the VPC and subnets where you want your instances to run.
  • Specify the group size (minimum capacity: 2, desired capacity: 2, maximum capacity: 5).
  • Configure scaling policies if needed, then choose "Next".
  • Configure notifications, tags, and other settings as needed.
  • Review and create the auto-scaling group.

Image description

Image description

Image description

Image description

3. Create a Network Load Balancer and Target Group

  • In the navigation pane, choose "Load Balancers".
  • Choose "Create Load Balancer".
  • Select "Network Load Balancer" and choose "Create".
  • Enter a name for your load balancer (e.g., MyNetworkLoadBalancer ).
  • Select the scheme (e.g., internet-facing ).
  • Choose the VPC and subnets.
  • Configure the listeners (protocol: TCP, port: 80).
  • Choose "Next".
  • Under "Configure routing", choose "Create a target group".
  • Enter a name for your target group (e.g., MyTargetGroup ).
  • Select the target type (e.g., instance ).
  • Configure the health checks (protocol: TCP, port: 80).
  • Choose "Next".
  • Register targets if needed, or choose "Next" if you want the auto-scaling group to manage targets.
  • Review and create the target group.

Image description

Image description

Image description

Image description

Image description

4. Attach Target Group to Auto Scaling Group

  • In the navigation pane, choose "Auto Scaling Groups".
  • Select your auto-scaling group ( MyASG ).
  • Choose the "Details" tab, then "Edit".
  • Under "Load balancing", select "Attach to a new load balancer".
  • Choose "Attach to an existing target group" and select your target group ( MyTargetGroup ).
  • Save the changes.

Image description

5. Verify Configuration

  • Ensure the instances are launched in the desired subnets and are healthy in the target group.
  • Test the network load balancer's DNS name to verify it distributes traffic to the instances.

Image description

Conclusion

These steps helps to successfully implement a Network Load Balancer in AWS, effectively distributing traffic across multiple EC2 instances managed by an Auto Scaling Group. This setup not only enhances the availability and reliability of applications but also ensures that the system can scale to meet varying levels of demand.

. . . . . . . . . . . . . .
Terabox Video Player