How to provision NLB in AWS EKS Fargate using Kubernetes

Shreyas Mhatre
2 min readJun 8, 2021

I want to provision Network load balancer i.e. NLB in AWS EKS Fargate using Kubernetes

Overview

You can create a network load balancer with IP or instance targets in AWS. You can use NLB instance targets with pods deployed to Amazon EC2 nodes, but not to Fargate.

To load balance network traffic across pods deployed to Fargate, you must use IP targets.

Prerequisite

Before setting up NLB,

  1. Ensure aws eks fargate is setup
  2. aws load balancer controller is installed (V2.2.0 or latest)
  3. Subnets are tagged for automatic subnet discovery. Refer https://aws.amazon.com/premiumsupport/knowledge-center/eks-vpc-subnet-discovery/

Kubernetes Annotation

To create a load balancer that uses IP targets, add the following annotation to a service manifest and deploy your service

service.beta.kubernetes.io/aws-load-balancer-type: "external" service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip"

NLBs are created as internal, by default. If you want to create an internet-facing NLB, add the following annotation:

service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"

Sample Example

In this example we will be creating internet facing (Public) Network Load Balancer. Ensure AWS vpc public subnet is correctly tag for auto-discovery as mentioned in prerequisite.

  1. Create sample deployment pod spec file

Apply the manifest

kubectl apply -f deployment.yaml

2. Create sample service file

Apply the manifest

kubectl apply -f service.yaml

This specification creates a new Service object named “nlb-deployment-service”, which targets application target TCP port on any Pod with the app=nlbtest label.

Kubernetes assigns this Service a AWS Load balancer endpoint.

Verify that the service was deployed.

Output

kubectl get svc nlb-deployment-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nlb-deployment-service LoadBalancer 10.100.xx.xx k8s-default-samplese-xxxxxxxxxx-xxxxxxxxxxxxxxxx.elb.us-east-1.amazonaws.com 25:25/TCP 4h

--

--