🌐 Setting Up a Network Load Balancer (NLB) on AWS
Learn how to set up a high-performance Network Load Balancer on AWS with detailed step-by-step instructions.
🚀 Step 1: Launch EC2 Instances
The EC2 instances are servers that host your application, and the NLB will distribute incoming traffic to these instances.
- 🔍 Navigate to EC2 Dashboard:
- Sign in to your AWS account and search for EC2 in the console search bar.
- 💻 Launch Instances:
- Click Launch Instances.
- Select an Amazon Machine Image (AMI), such as Amazon Linux 2 AMI.
- Choose an Instance Type (e.g., t2.micro for testing).
- Click Next: Configure Instance Details.
- ⚙️ Configure Instance Details:
- Ensure instances are in the same VPC and select different Availability Zones for high availability.
- Enable Auto-assign Public IP for internet access.
- 🏷️ Add Tags (Optional):
- Add tags like
Name=MyInstance1to identify resources.
- Add tags like
- 🔒 Configure Security Group:
- Create a new or use an existing security group.
- Add inbound rules to allow traffic (e.g.,
HTTP,TCP).
- 🔑 Launch and Access Key Pair:
- Choose an existing or create a new key pair for SSH access.
- Launch the instances and wait for them to reach
Runningstatus.
🛠️ Step 2: Create a Target Group
A Target Group is a logical grouping of your instances that the NLB will direct traffic to.
- 🔍 Navigate to Target Groups:
- Go to the EC2 Dashboard and find Target Groups under Load Balancing.
- 📋 Create Target Group:
- Click Create target group.
- Choose
Instancesas the target type and configure settings like protocol (TCP) and port (e.g.,80).
- 💉 Configure Health Checks:
- Set protocol to
TCPand configure thresholds and timeouts.
- Set protocol to
- ✅ Register Targets (Instances):
- Select and include the instances in the target group.
🔄 Step 3: Create a Network Load Balancer
The Network Load Balancer distributes traffic to your instances based on Layer 4 protocols like TCP.
- 🔍 Navigate to Load Balancers:
- Under Load Balancing, select Load Balancers.
- ⚙️ Configure NLB Basic Settings:
- Set up a name, scheme (e.g.,
Internet-facing), and IP address type (e.g.,IPv4).
- Set up a name, scheme (e.g.,
- 📜 Configure Listeners and Routing:
- Define the listener port and protocol, and associate the target group created earlier.
- 🌍 Availability Zones and Subnets:
- Select subnets across multiple availability zones for high availability.
🔐 Step 4: Configure Security Groups
Security groups act as firewalls for your EC2 instances, controlling traffic flow.
- 🔒 Allow Traffic from the NLB:
- Edit security group inbound rules to allow traffic from the NLB’s IP range.
🔍 Step 5: Test the Load Balancer
- 🌐 Get DNS Name of NLB:
- Find the DNS name of your NLB in the Load Balancers section.
- 📡 Test Traffic Routing:
- Send requests to the DNS name via a web browser or
curl.
- Send requests to the DNS name via a web browser or
📈 Step 6: Monitor and Manage the NLB
- 📊 Monitor with CloudWatch:
- View metrics like HealthyHostCount and ActiveFlowCount.
- 🔄 Adjust Target Group Settings:
- Add more instances or tweak health checks as needed.
🎉 Congratulations! You’ve successfully set up a Network Load Balancer on AWS. For advanced configurations, explore AWS documentation.
