Sub topic 10
Exposing Services Through ALB and NLB
This chapter assumes you can deploy a Deployment and Service with kubectl, and that you know what an Application Load Balancer (ALB) and Network Load Balancer (NLB) are in AWS. It also assumes the web Deployment and Service from the earlier deployment chapter are running, and that you have an IAM role for the controller (see the chapter on pod AWS permissions).
Why a ClusterIP Service Is Not Enough
A ClusterIP Service is reachable only from inside the cluster. To accept traffic from the internet, you need a load balancer in front of your pods. On EKS, the AWS Load Balancer Controller creates and manages AWS load balancers for you. It watches Kubernetes objects and calls the AWS APIs.
- An Ingress becomes an ALB (layer 7, HTTP and HTTPS).
- A Service of type LoadBalancer becomes an NLB (layer 4, TCP, UDP and TLS).
The controller is not installed by default. You install it, usually with Helm, and give it an IAM role through IRSA or Pod Identity so it can create load balancers, target groups and security group rules.
How Traffic Reaches Pods
The controller supports two target types. The choice affects the network path.
| Target type | Traffic goes to | Notes |
|---|---|---|
| `ip` | Pod IP directly | Works because the VPC CNI gives pods VPC addresses. Skips an extra hop. Required for Fargate. |
| `instance` | Node port on each node | Traffic is then forwarded by kube-proxy to a pod, possibly on another node. |
Exposing the App with an ALB
Apply this Ingress. It uses the web Service from the earlier chapter.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
ingressClassName: alb
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80The scheme annotation makes the ALB public. Without it, the ALB is internal. The target-type: ip annotation sends traffic straight to pods. Check progress with kubectl get ingress web. After a few minutes the ADDRESS column shows the ALB DNS name.
Exposing a Service with an NLB
For non-HTTP traffic, or when you need static IPs and very low latency, use a Service. The annotations below make the controller create an NLB.
apiVersion: v1
kind: Service
metadata:
name: web-nlb
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: external
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
spec:
type: LoadBalancer
selector:
app: web
ports:
- port: 80
targetPort: 80The external type tells Kubernetes to leave the Service to the AWS Load Balancer Controller. Without it, the older in-tree provider creates a Classic Load Balancer or a legacy NLB.
Common Errors
- Ingress has no ADDRESS. Read the controller logs with
kubectl logs -n kube-system deployment/aws-load-balancer-controller. A missing or too-narrow IAM policy is the usual cause. - No load balancer is created at all. Check that
ingressClassName: albis set, and that the controller pods are running. - Subnet discovery fails. The controller finds subnets by tag. Public subnets need
kubernetes.io/role/elb=1. Private subnets needkubernetes.io/role/internal-elb=1. - Targets stay unhealthy. The pod must listen on the port the Service targets. Also confirm that the node or pod security groups allow traffic from the load balancer.
Exercise
Your Ingress has been applied but kubectl get ingress shows an empty ADDRESS, and the controller logs report that it cannot discover subnets. What should you check, and which annotation or tag is involved?
Show answer
Check the tags on the VPC subnets. Public subnets for an internet-facing ALB need the tag kubernetes.io/role/elb=1. Private subnets for an internal load balancer need kubernetes.io/role/internal-elb=1. After adding the tags, the controller retries and the ADDRESS is filled in.
Exercise
Why does the ip target type need the Amazon VPC CNI, and when would you be forced to use it?
Show answer
The VPC CNI gives each pod a real VPC IP address, so the load balancer can register pod IPs as targets directly. It is required for pods on Fargate, which have no node ports to target.