Amazon EKS — Load Balancing — Practice Exercises
Chapter 10 — Practice Exercises
Exercise 1: ALB vs NLB
Question: You have 3 services: HTTP REST API, gRPC service, and a WebSocket chat app. Which load balancer type would you use for each and why?
Show Solution
| Service | LB Type | Why |
|---|---|---|
| HTTP REST API | ALB | Layer 7, path routing, SSL termination |
| gRPC service | NLB | gRPC uses HTTP/2 over TCP; NLB preserves connection |
| WebSocket chat | ALB | ALB supports WebSocket natively with sticky sessions |
Note: ALB also supports gRPC (since 2020), so ALB could work for all three. NLB is preferred for gRPC when you need static IPs or ultra-low latency.
Exercise 2: HTTPS Ingress
Question: Write a complete Ingress resource that: serves app.example.com on HTTPS, redirects HTTP to HTTPS, uses an ACM certificate, targets pods directly (ip mode), and shares an ALB with other services.
Show Solution
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: app-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:123456789012:certificate/abc-123
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80},{"HTTPS":443}]'
alb.ingress.kubernetes.io/ssl-redirect: "443"
alb.ingress.kubernetes.io/group.name: shared-alb
spec:
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: app-service
port:
number: 80
Exercise 3: Multi-Service Routing
Question: Design an Ingress that routes: example.com/ → frontend, example.com/api/v1 → api-v1, example.com/api/v2 → api-v2, admin.example.com → admin panel.
Show Solution
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: multi-service
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
rules:
- host: example.com
http:
paths:
- path: /api/v2
pathType: Prefix
backend:
service:
name: api-v2
port:
number: 80
- path: /api/v1
pathType: Prefix
backend:
service:
name: api-v1
port:
number: 80
- path: /
pathType: Prefix
backend:
service:
name: frontend
port:
number: 80
- host: admin.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: admin
port:
number: 80
Order matters: /api/v2 and /api/v1 must come before / to avoid the catch-all matching first.
Exercise 4: Troubleshoot ALB
Question: You created an Ingress but no ALB is being provisioned. kubectl get ingress shows no ADDRESS. List 5 things to check.
Show Solution
# 1. Check LB controller is running
$ kubectl get pods -n kube-system -l app.kubernetes.io/name=aws-load-balancer-controller
# 2. Check controller logs
$ kubectl logs -n kube-system -l app.kubernetes.io/name=aws-load-balancer-controller
# 3. Check Ingress events
$ kubectl describe ingress <name>
# Look for events like "Failed to create ALB"
# 4. Check subnet tags
$ aws ec2 describe-subnets --filters "Name=tag-key,Values=kubernetes.io/role/elb"
# Public subnets need: kubernetes.io/role/elb = 1
# 5. Check IRSA permissions
$ kubectl describe sa aws-load-balancer-controller -n kube-system
# Should have eks.amazonaws.com/role-arn annotation
Exercise 5: Cost Optimization
Question: You have 10 microservices, each with its own Ingress creating a separate ALB. At $18/month per ALB, that’s $180/month. How do you reduce this?
Show Solution
Use Ingress groups to share a single ALB:
# Service 1
annotations:
alb.ingress.kubernetes.io/group.name: shared-alb
alb.ingress.kubernetes.io/group.order: "1"
# Service 2
annotations:
alb.ingress.kubernetes.io/group.name: shared-alb
alb.ingress.kubernetes.io/group.order: "2"
# ... repeat for all 10 services
Result:
- Before: 10 ALBs × $18 = $180/month
- After: 1 ALB × $18 = $18/month
- Savings: $162/month (90%)
You pay slightly more in LCU (load capacity units) since one ALB handles all traffic, but it’s still far cheaper than 10 ALBs.
What’s Next?
Automatic scaling: Chapter 11 — Auto Scaling.