What is Network Load Balancer?
AWS Tutorials
By
KnowledgeHut
A load balancer can be used as a single point of contact for the clients. This balancer distributes the incoming requests to multiple targets, and one such target is the Amazon EC2 instance. When requests are spread out, the availability of the service improves.Elastic Load balancing supports the below mentioned type of load balancers:Application Load Balancers Network Load Balancers Classic Load Balancers A load balancer can be provided with a ‘listener’ that helps in checking for connection requests that come from clients. This listener uses a protocol and a port which is configured by the user, and forward the request from the client to a specific ‘target group’. A target group can be understood as a router which helps in routing the requests from one or multiple registered targets (one such example is an Amazon EC2 instance) with the help of a TCP protocol and the port (which is configured by the user). The target can be registered with multiple other target groups. Health checks can be configured on a per-target group basis. These health checks are performed on all targets that are associated with a target group (this is specified in a listener rule that is used with the load balancer). A network load balancer works in the fourth layer of the OSI model (Open Systems Interconnection). It has the capability to respond to millions of request every second. When a load balancer receives a connection request, it selects one target from the target group to assign a default rule. A TCP connection is tried to connect to the selected target wherein the port through which this connection happens is configured by the user in the listener configuration. When an Availability Zone is enabled for the load balancer, the Elastic Load Balancing creates a load balancer node in this Availability Zone. Every load balancer node distributes the incoming traffic to registered targets in their Availability Zone (of target groups) by default. An Elastic Load Balancing helps in the creation of a network interface for every Availability Zone that is enabled. Every load balancer node in this Availability Zone uses this interface to obtain a static IP address. When an Internet-facing load balancer is created, an elastic IP address per subnet can be associated optionally to the node. When a target group is created, the user specifies the target type that is used to determine whether the targets are registered by instance ID or IP address.If a target is registered with the help of an instance ID, the source IP address of the client is stored and provisioned to the user applications.If the target is registered with an IP address, the source IP address is private IP address of the load balancer node.Targets can be removed or added as and when required from the load balancer. This will not affect the overall request flow to the user application. Elastic Load Balancing can be used to scale the traffic as and when the user application changes with time. Elastic Load Balancing helps in scaling a majority of workloads automatically.Health checks for these applications can be configured which will be used to monitor the registered target’s health so that the load balancer gets to send requests to the healthy targets only.Pre-requisitesAvailability Zone used with the EC2 instance needs to be specified. VPC has to be configured with at least one public subnet in every Availability Zone. These public subnets are used in configuring the load balancer. The EC2 instance can be launched with other subnets present in the same Availability Zone. At least one EC2 instance should be launched in every Availability Zone that will allow the TCP access from clients which is present on the listener port. This way, the health check requests would also be allowed from the VPC. Features of Network Load BalancerCan be used to handle varying sized workloads. Can respond to millions of requests from applications per second. It supports static IP address for the load balancer. An Elastic IP address can also be assigned to every subnet that is enabled for the load balancer. It supports registering targets based on IP addresses, and this includes targets which are outside the VPC of the load balancer.It supports routing requests of multiple applications which are present on a single EC2 instance. Every instance can be registered or an IP address that has the same target group which uses multiple ports can be specified.It provides support to containerized applications. ECS can be used to select an unused port when it schedules a task. This task can be registered with a specific target group using the same port. This way, the clusters can be efficiently used.Every service’s health can be monitored separately, and these health checks are defined at the target group level. In addition to this, CloudWatch metrics are associated with the target group level.When a target group is associated with an Auto Scaling group, it enables the user to scale every service dynamically based on the requirement and requests.Steps to begin working with a Network Load BalancerFollowing are the steps to begin working with a Network Load Balancer: Choosing a load balancer typeOpen the Amazon EC2 console. On the navigation bar, select an appropriate region for the load balancer. Choose the same region for EC2 instances as well. In the ‘Navigation pane’ under ‘Load balancing’, click on ‘Load Balancers’. Click on ‘Create Load Balancer’. For ‘Network Load Balancer’, click on ‘Create’. Configuring load balancer and listener On ‘Configure Load Balancer’ page, enter a name for the load balancer. The name must be unique within the set of Application Load Balancers. Keep the default value for the ‘Scheme’, i.e internet-facing. Keep the default value for the ‘Listeners’, which accepts TCP traffic on port 80. In Availability Zones, select the same VPC which is used with EC2 instances. Click on ‘Next: Configure Routing’. Configuring target type Target group is used for routing the request. The listener rule routes the requests to the targets that have been registered with thin target group. The load balancer is used to check the health of target in this target group. In the ‘Configure Routing’ page, follow the below steps: Keep the default for ‘Target Group‘. Enter a ‘Name’ for the new ‘Target Group’. The ‘Protocol’ should be TCP, and ‘Port’ should be 80, and ‘Target Type’ is the instance. In ‘Health Checks’, let the default protocol be. Click on ‘Next: Register Targets’. Register target with target group In the ‘Register Targets’ page, select one or more ‘Instances’. Let the default port be 80 and choose the ‘Add to registered’. Once selection of instances in done, click on ‘Next: Review’. Create and test the load balancer On the ‘Review’ page, select ‘Create’. Once the load balancer has been created, and the notification says so, click on ‘Close’. In the navigation pane, under ‘Load balancing’, click on ‘Target groups’. Select the newly created target group. Click on ‘Targets’ and make sure the instances are ready. In the navigation pane, under ‘Load balancing’, click on ‘Load balancers’. Select the newly created load balancer. Click on the ‘Description’, and note down the DNS name of the load balancer. Paste this DNS name in the address filed of a web browser (with working internet connection). If everything works well, the browser will display the default page of the server. ConclusionIn this post, we understood how Network Load Balancers can be used to efficiently manage traffic and serve millions of requests per second.