Skip to main content

Creating and Configuring a Network Load Balancer in AWS

Hands-On Lab

 

Photo of Craig Arcuri

Craig Arcuri

AWS Training Architect II in Content

Length

01:15:00

Difficulty

Advanced

In the learning activity, the student will learn about Network Load Balancers. The lesson will take a deeper dive into the Network Load Balancer, presenting its features and use case, and highlighting comparisons between the Network Load Balancer and the Application Load Balancer. The student will walk through preparing the AWS environment for the Network Load Balancer (configuring subnets, network ACL, and EC2 instances). When the preparation is complete, the student will create and configure a Network Load Balancer. After configuration of the Load Balancer, the student will work from the CLI to run a small test on the Load Balancer and view the results in the CloudWatch Monitor.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Creating and Configuring a Network Load Balancer in AWS

Introduction

In this hands-on lab, we prepare the AWS environment for the Network Load Balancer (configuring subnets, network ACL, and EC2 instances). When the preparation is complete, we will create and configure a Network Load Balancer. After configuration of the load balancer, we will work from the CLI to run a small test on the load balancer and view the results in the CloudWatch Monitor.

Solution

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

Prepare the Environment

Create and Configure a Subnet

  1. Navigate to EC2, and click to view our one running instance.
  2. In a new browser tab, navigate to VPC.
  3. Click Subnets in the left-hand menu, and then click Create subnet.
    • Name tag: Public B
    • VPC: Select the listed VPC
    • Availability Zone: us-east-1b
    • IPv4 CIDR block: 10.0.2.0/24
  4. Click Create.
  5. On the subnets page, with the new subnet selected, click the Route Table tab below.
  6. Click the route table link.
  7. With it selected, click the Routes tab below.
  8. Click Edit, and then Add another route.
  9. Set the following values:
    • Destination: 0.0.0.0/0
    • Target: Select the listed internet gateway
  10. Click Save.
  11. Click the Subnet Associations tab.
  12. Click Edit.
  13. Select the Public B subnet, and click Save.

Edit the Network ACL

Note: Instead of the 100 ALL Traffic Allow Rule, change it to http Allow.

  1. Click Subnets in the left-hand menu.
  2. Click the Network ACL tab below, and then click the network ACL link.
  3. With it selected, click the Inbound Rules tab.
  4. Click Edit, and then click Add another rule.
  5. Set the following values:
    • Rule #: 101
    • Type: HTTPS (443)
    • Protocol: TCP (6)
    • Port Range: 443
    • Source: 0.0.0.0/0
  6. Click Add another rule.
  7. Set the following values:
    • Rule #: 102
    • Type: SSH (22)
    • Protocol: TCP (6)
    • Port Range: 22
    • Source: 0.0.0.0/0
  8. Click Add another rule.
  9. Set the following values:
    • Rule #: 103
    • Type: Custom TCP Rule
    • Protocol: TCP (6)
    • Port Range: 1024 - 65535
    • Source: 0.0.0.0/0
  10. Click Save.

Create EC2 Instances

First Instance
  1. In the EC2 browser tab, click the running instances.
  2. Click Launch Instance.
  3. On the AMI page, select the Amazon Linux 2 AMI.
  4. Leave t2.micro selected, and click Next: Configure Instance Details.
  5. On the Configure Instance Details page:
    • Network: Leave default
    • Subnet: us-east-1a
    • Auto-assign Public IP: Enable
  6. Click Next: Add Storage, Next: Add Tags, and then Next: Configure Security Group.
  7. Click to Select an existing security group.
  8. Select the provided security group (not the default security group) from the table.
  9. Click Review and Launch, and then Launch.
  10. In the key pair dialog, select Create a new key pair.
  11. Give it a Key pair name of "nlb".
  12. Click Download Key Pair, and then Launch Instances.
  13. Click View Instances.
Second Instance
  1. Click Launch Instance.
  2. On the AMI page, select the Amazon Linux 2 AMI.
  3. Leave t2.micro selected, and click Next: Configure Instance Details.
  4. On the Configure Instance Details page:
    • Network: Leave default
    • Subnet: us-east-1b
    • Auto-assign Public IP: Enable
  5. Click Next: Add Storage, Next: Add Tags, and then Next: Configure Security Group.
  6. Click to Select an existing security group.
  7. Select the provided security group (not the default security group) from the table.
  8. Click Review and Launch, and then Launch.
  9. In the key pair dialog, select Choose an existing key pair.
  10. Select nlb, and then Launch Instances.
  11. Click View Instances, and give them a few minutes to enter the running state.

Create and Configure a Network Load Balancer

  1. Click Load Balancers in the left-hand menu.
  2. Click Create Load Balancer.
  3. In the Network Load Balancer card, click Create.
  4. In the Basic Configuration section, set the following values:
    • Name: NLB4LA
    • Scheme: internet-facing
  5. Leave the settings in the Listeners section as-is.
  6. In the Availability Zones section, select the listed VPC.
  7. Check both availability zones.
  8. Click Next: Configure Routing.
  9. In the Target Group section, set the following values:
    • Target group: New target group
    • Name: nlbTarget
    • Protocol: TCP
    • Port: 80
    • Target type: instance
  10. In the Health checks section, set the following values:
    • Protocol: TCP
  11. Leave the settings in the Advanced health check settings section as-is.
  12. Click Next: Register Targets.
  13. Select the two instances we created (not the AdminInstance), and click Add to registered.
  14. Click Next: Review.
  15. Click Create.
  16. Click Target Groups in the left-hand menu.
  17. In the Targets tab, after a minute or two, we should see the instances are unhealthy.

Test and Monitor the Network Load Balancer

Configure Instances as Web Servers

Configure First Instance as a Web Server
  1. Open a terminal session.

  2. Make sure you're in your downloads directory.

  3. On the instances page of the AWS console, select one of our instances and click Connect.

  4. Copy the chmod command in the dialog, and run it in the terminal.

  5. In the connection dialog, copy the ssh command, and run it in the terminal.

  6. Run a YUM update:

    sudo yum update -y
  7. Install Apache:

    sudo yum install -y httpd
  8. Ensure the web server starts if the instance is rebooted:

    sudo service httpd start
  9. Automate the web server starting:

    sudo chkconfig httpd on
  10. Log out of the instance:

    exit
Configure Second Instance as a Web Server
  1. On the instances page of the AWS console, select our other instance and click Connect.

  2. Copy the ssh command, and run it in the terminal.

  3. Run the same series of commands:

    sudo yum update -y
    
    sudo yum install -y httpd
    
    sudo service httpd start
    
    sudo chkconfig httpd on
  4. Log out of the instance:

    exit

Check Health Checks and Test Network Load Balancer

  1. In the AWS console, click Target Groups in the left-hand menu.

  2. In the Targets tab, after a minute or two, we should see the instances are now healthy.

  3. Click Load Balancers in the left-hand menu.

  4. Copy its DNS name, and paste it into a new browser tab. It should result in the Apache test page.

  5. In the AWS console, click Instances in the left-hand menu.

  6. Click our running instances, select the AdminInstance, and copy its public IP address.

  7. In the terminal, log in to it:

    ssh linuxacademy@<PUBLIC IP OF ADMININSTANCE>

    The password is 123456.

  8. In the AWS console, click Load Balancers in the left-hand menu.

  9. In the Description tab, copy the DNS name and paste it into a text file. We'll need it for the next command.

  10. In the Monitoring tab, keep an eye on the CloudWatch metrics.

  11. In the terminal, we'll bombard our load balancer with requests while monitoring the CloudWatch metrics in the AWS console. Run the following commands:

    while true;

    Hit new line.

    do

    Hit new line.

    wget <LOAD BALANCER DNS NAME>

    Hit new line.

    done
  12. Hit Return — your terminal will most likely go crazy.

  13. Hit Ctrl+C to get out of the loop.

  14. In the AWS console, take a look at the Monitoring tab of our load balancer. We should see the spikes in the different charts.

Conclusion

Congratulations on completing this hands-on lab!