Offload Reconciliation of NLB to LBC Using Annotation¶
In this demo, we will use service.beta.kubernetes.io/aws-load-balancer-type: external annotation to offload the reconciliation of Network Load Balancer (NLB) to AWS Load Balancer Controller (LBC).
Note
If you configure service.beta.kubernetes.io/aws-load-balancer-type: external, you must provide the service.beta.kubernetes.io/aws-load-balancer-nlb-target-type annotation and set it to either instance or ip.
Docker Images¶
Here is the Docker Image used in this tutorial: reyanshkharga/nodeapp:v1
Note
reyanshkharga/nodeapp:v1 runs on port 5000 and has the following routes:
GET /Returns host info and app versionGET /healthReturns health status of the appGET /randomReturns a randomly generated number between 1 and 10
Step 1: Create a Deployment¶
First, let's create a deployment as follows:
Apply the manifest to create the deployment:
Verify deployment and pods:
Step 2: Create a Service¶
Now, let's create a LoadBalancer service but this time we'll offload the reconciliation of NLB to LBC using .spec.loadBalancerClass field.
Note
The service.beta.kubernetes.io/aws-load-balancer-nlb-target-type annotation is mandatory when you use the service.beta.kubernetes.io/aws-load-balancer-type: external annotation to offload the reconciliation of NLB to LBC.
Also, to create an internet-facing NLB, the following annotation is required on your service:
Apply the manifest to create the service:
Verify service:
Step 3: Verify the Network Load Balancer (NLB) in AWS Console¶
Visit AWS Console and verify that a network load balancer (NLB) was created.
Also, verify that the NLB was created by AWS Load Balancer Controller. You can check the events in the logs as follows:
kubectl logs -f deploy/aws-load-balancer-controller -n aws-load-balancer-controller --all-containers=true
Step 4: Access App Via Network Load Balancer DNS¶
Once the load balancer is in Active state, you can hit the load balancer DNS and verify if everything is working properly.
Access the load balancer DNS by entering it in your browser. You can get the load balancer DNS either from the AWS console or the service configuration.
Try accessing the following paths:
Clean Up¶
Assuming your folder structure looks like the one below:
Let's delete all the resources we created: