|
| 1 | +--- |
| 2 | +title: AWS Load Balancer Controller - NLB Basics |
| 3 | +description: Learn to use AWS Network Load Balancer with AWS Load Balancer Controller |
| 4 | +--- |
| 5 | + |
| 6 | +## Step-01: Introduction |
| 7 | +- Understand more about |
| 8 | + - **AWS Cloud Provider Load Balancer Controller (Legacy):** Creates AWS CLB and NLB |
| 9 | + - **AWS Load Balancer Controller (Latest):** Creates AWS ALB and NLB |
| 10 | +- Understand how the Kubernetes Service of Type Load Balancer which can create AWS NLB to be associated with latest `AWS Load Balancer Controller`. |
| 11 | +- Understand various NLB Annotations |
| 12 | + |
| 13 | + |
| 14 | +## Step-02: Review 01-Nginx-App3-Deployment.yml |
| 15 | +- **File Name:** `kube-manifests/01-Nginx-App3-Deployment.yml` |
| 16 | +```yaml |
| 17 | +apiVersion: apps/v1 |
| 18 | +kind: Deployment |
| 19 | +metadata: |
| 20 | + name: app3-nginx-deployment |
| 21 | + labels: |
| 22 | + app: app3-nginx |
| 23 | +spec: |
| 24 | + replicas: 1 |
| 25 | + selector: |
| 26 | + matchLabels: |
| 27 | + app: app3-nginx |
| 28 | + template: |
| 29 | + metadata: |
| 30 | + labels: |
| 31 | + app: app3-nginx |
| 32 | + spec: |
| 33 | + containers: |
| 34 | + - name: app2-nginx |
| 35 | + image: stacksimplify/kubenginx:1.0.0 |
| 36 | + ports: |
| 37 | + - containerPort: 80 |
| 38 | + |
| 39 | +``` |
| 40 | + |
| 41 | +## Step-03: Review 02-LBC-NLB-LoadBalancer-Service.yml |
| 42 | +- **File Name:** `kube-manifests\02-LBC-NLB-LoadBalancer-Service.yml` |
| 43 | +```yaml |
| 44 | +apiVersion: v1 |
| 45 | +kind: Service |
| 46 | +metadata: |
| 47 | + name: basics-lbc-network-lb |
| 48 | + annotations: |
| 49 | + # Traffic Routing |
| 50 | + service.beta.kubernetes.io/aws-load-balancer-name: basics-lbc-network-lb |
| 51 | + service.beta.kubernetes.io/aws-load-balancer-type: external |
| 52 | + service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: instance |
| 53 | + #service.beta.kubernetes.io/aws-load-balancer-subnets: subnet-xxxx, mySubnet ## Subnets are auto-discovered if this annotation is not specified, see Subnet Discovery for further details. |
| 54 | + |
| 55 | + # Health Check Settings |
| 56 | + service.beta.kubernetes.io/aws-load-balancer-healthcheck-protocol: http |
| 57 | + service.beta.kubernetes.io/aws-load-balancer-healthcheck-port: traffic-port |
| 58 | + service.beta.kubernetes.io/aws-load-balancer-healthcheck-path: /index.html |
| 59 | + service.beta.kubernetes.io/aws-load-balancer-healthcheck-healthy-threshold: "3" |
| 60 | + service.beta.kubernetes.io/aws-load-balancer-healthcheck-unhealthy-threshold: "3" |
| 61 | + service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval: "10" # The controller currently ignores the timeout configuration due to the limitations on the AWS NLB. The default timeout for TCP is 10s and HTTP is 6s. |
| 62 | + |
| 63 | + # Access Control |
| 64 | + service.beta.kubernetes.io/load-balancer-source-ranges: 0.0.0.0/0 |
| 65 | + service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing" |
| 66 | + |
| 67 | + # AWS Resource Tags |
| 68 | + service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags: Environment=dev,Team=test |
| 69 | +spec: |
| 70 | + type: LoadBalancer |
| 71 | + selector: |
| 72 | + app: app3-nginx |
| 73 | + ports: |
| 74 | + - port: 80 |
| 75 | + targetPort: 80 |
| 76 | +``` |
| 77 | +
|
| 78 | +## Step-04: Deploy all kube-manifests |
| 79 | +```t |
| 80 | +# Deploy kube-manifests |
| 81 | +kubectl apply -f kube-manifests/ |
| 82 | + |
| 83 | +# Verify Pods |
| 84 | +kubectl get pods |
| 85 | + |
| 86 | +# Verify Services |
| 87 | +kubectl get svc |
| 88 | +Observation: |
| 89 | +1. Verify the network lb DNS name |
| 90 | + |
| 91 | +# Verify AWS Load Balancer Controller pod logs |
| 92 | +kubectl -n kube-system get pods |
| 93 | +kubectl -n kube-system logs -f <aws-load-balancer-controller-POD-NAME> |
| 94 | + |
| 95 | +# Verify using AWS Mgmt Console |
| 96 | +Go to Services -> EC2 -> Load Balancing -> Load Balancers |
| 97 | +1. Verify Description Tab - DNS Name matching output of "kubectl get svc" External IP |
| 98 | +2. Verify Listeners Tab |
| 99 | + |
| 100 | +Go to Services -> EC2 -> Load Balancing -> Target Groups |
| 101 | +1. Verify Registered targets |
| 102 | +2. Verify Health Check path |
| 103 | + |
| 104 | +# Access Application |
| 105 | +http://<NLB-DNS-NAME> |
| 106 | +``` |
| 107 | + |
| 108 | +## Step-05: Clean-Up |
| 109 | +```t |
| 110 | +# Delete or Undeploy kube-manifests |
| 111 | +kubectl delete -f kube-manifests/ |
| 112 | + |
| 113 | +# Verify if NLB deleted |
| 114 | +In AWS Mgmt Console, |
| 115 | +Go to Services -> EC2 -> Load Balancing -> Load Balancers |
| 116 | +``` |
| 117 | + |
| 118 | +## References |
| 119 | +- [Network Load Balancer](https://docs.aws.amazon.com/eks/latest/userguide/network-load-balancing.html) |
| 120 | +- [NLB Service](https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/service/nlb/) |
| 121 | +- [NLB Service Annotations](https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/service/annotations/) |
0 commit comments