2024-11-01Hünkar Döner

What is AWS Load Balancer Controller? How to Use with EKS?

AWSEKSALBIngressNetworking
W

What is AWS Load Balancer Controller?

In the Kubernetes world, "Ingress" or "Service (LoadBalancer)" resources are used to bring external traffic in. However, Kubernetes alone does not know how to create AWS Load Balancers (ALB/NLB).

Here, AWS Load Balancer Controller (LBC) is an add-on that fills this gap. LBC listens to the Kubernetes API, and when you create an Ingress resource, it goes and creates an Application Load Balancer (ALB) on the AWS side and routes traffic to your pods.

Features

  • ALB Management (L7): Automatically creates ALB for Ingress resources. Performs SSL termination, content-based routing.
  • NLB Management (L4): Creates Network Load Balancer (NLB) for resources with Service type LoadBalancer. Provides high performance.
  • IP Target Mode: Routes traffic directly to Pod IP, not via NodePort. This reduces latency.

Installation on EKS

1. IAM Policy

LBC needs an IAM role to talk to the AWS API (create, delete LB). Download the required JSON policy from AWS and create an IAM Policy.

2. Service Account (IRSA)

Create a Kubernetes Service Account that will use this IAM policy. The eksctl create iamserviceaccount ... command does this easily.

3. Installation with Helm

helm repo add eks https://aws.github.io/eks-charts
helm install aws-load-balancer-controller eks/aws-load-balancer-controller   -n kube-system   --set clusterName=my-cluster   --set serviceAccount.create=false   --set serviceAccount.name=aws-load-balancer-controller

How to Use?

After installation, create an Ingress file and add the kubernetes.io/ingress.class: alb annotation.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-service
                port:
                  number: 80

When you apply this file (kubectl apply), you will see a new ALB being created in the AWS console. LBC is the cornerstone of EKS networking structure in AWS Consultancy projects.