A cheat sheet for using Amazon Elastic Load Balancing — Classic Load Balancer, Network Load Balancer & Application Load Balancer with Amazon Elastic Container Service for Kubernetes (EKS)
The two resources for Amazon EKS that I usually refer are https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html and the AWS Kubernetes workshop available at https://github.com/aws-samples/aws-workshop-for-kubernetes .
I needed a handy guide where I could document my “unofficial” cheat sheet as a ready reference for using the various AWS Load Balancers with services deployed on EKS.
The following are a summary of the steps involved, which I collated from various sources on the web. Please note the official documentation takes precedence and the following steps are only a pointer to get you started ..
Using Classic Elastic Load Balancer with EKS
This is covered in more detail at https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer
A sample service definition file, service-elb.yaml is given below.
apiVersion: v1
kind: Service
metadata:
name: echo-service
spec:
selector:
app: echo-pod
ports:
— name: http
protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer
Apply the service file using kubectl
kubectl apply -f service-elb.yaml
<< wait for sometime for the ELB to be provisioned >>
ELB_ADDRESS=$(kubectl get svc echo-service -o jsonpath={.status.loadBalancer.ingress[0].hostname}’)
curl http://$ELB_ADDRESS
<< clean up services >>
kubectl delete -f service-elb.yaml
Using Network Load Balancer (NLB) with EKS
Reference: https://aws.amazon.com/blogs/opensource/network-load-balancer-support-in-kubernetes-1-9/
A sample service definition file, service-nlb.yaml is given below (please note the annotation for “nlb”).
apiVersion: v1
kind: Service
metadata:
name: nginx
namespace: default
labels:
app: nginx
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: “nlb”
spec:
externalTrafficPolicy: Local
ports:
— name: http
port: 80
protocol: TCP
targetPort: 80
selector:
app: nginx
type: LoadBalancer
Apply the files using kubectl
kubectl run nginx — image=nginx — port=80 — labels app=nginx
kubectl apply -f service-nlb.yaml
NLB_ADDRESS=$(kubectl get svc nginx -o jsonpath=’{.status.loadBalancer.ingress[0].hostname}’)
<< Wait for sometime for the NLB to get provisioned >>
curl http://$NLB_ADDRESS
<< Delete the service >>
kubectl delete -f service-nlb.yaml
Using Application Load Balancer (ALB) with EKS
This integration is based on the ALB Ingress controller from CoreOS — https://github.com/kubernetes-sigs/aws-alb-ingress-controller
Please also refer to https://github.com/aws-samples/aws-workshop-for-kubernetes/tree/master/04-path-security-and-networking/405-ingress-controllers for more detailed information.
I used the sample application and the detailed steps from the github post at https://github.com/pahud/eks-alb-ingress and in the end I had a ALB running in no time. Thanks Pahud !!
Check the AWS console — EC2/Load Balancers section to see if the ALB has been provisioned ..
curl “http://<YOUR_ALB_DNS_NAME>/greeting?name=Mani”