Deploying the AWS Loadbalancer Controller to an EKS Cluster to produce ALB Ingress resources.
Now a days, lots of projects uses loadbalancers to manage their traffic. Based on that, Application loadbalancers makes to you to do the deploy in cost-effective way.
In this tutorial, I’m going to show how we’re going to deploy the aws loadbalancer controller to an EKS cluster and make an ingress to our applications.
An Application Load Balancer (ALB) controller is a Kubernetes controller that manages the creation and configuration of Application Load Balancers (ALBs) in an Amazon Web Services (AWS) Elastic Load Balancing (ELB) service. It automatically creates and configures ALBs for Kubernetes services that are annotated with specific labels, and it automatically updates the ALB configuration when the service or its associated pods are updated. This allows for easy and automated management of load balancing for Kubernetes applications on AWS.
The Application Load Balancer (ALB) controller connects to Kubernetes by watching for the creation and updates of Kubernetes resources, such as Services and Ingresses. When a new Service or Ingress is created or updated with certain annotations, the ALB controller automatically creates or updates an Application Load Balancer (ALB) to match the desired configuration.
An Ingress resource in Kubernetes is a way to configure external access to services within a cluster. It defines rules for routing incoming traffic to different services based on the hostname or path of the request. By using specific annotations on an Ingress resource, the ALB controller can automatically configure the Application Load Balancer (ALB) to route traffic to the correct service based on the rules defined in the Ingress resource.
Before you plan to deploy this deployment, you have to add these set of tags to your private and public subnets. Otherwise, it will not create an ingress endpoint for your application domain.
Hence, add this tag for the private subnets;
"kubernetes.io/cluster/<EKS-CLUSTER-NAME>" = "owned"
"kubernetes.io/role/internal-elb" = "1"
And this tag for the public subnets;
"kubernetes.io/cluster/<EKS-CLUSTER-NAME>" = "owned"
"kubernetes.io/role/elb" = "1"
Once you add those tags to your particular subnets, you can start the deployment.
To do this deployment, I’ve created a shell script. Please follow the below script and change some of the names accordingly.
Before you deploy this to your EKS cluster, you have to add this deploy.yaml and iam_policy.json to your directory.
deploy.yaml
Once you add those files to your directory, you can start the deployment by using below command.
.\alb.sh
Once you successfully done the deployment you will see it as below on your cluster.
Awesome!! now you have successfully deployed the aws loadbalancer controller to your EKS cluster!! 🎉🎉
Then, you can deploy more applications and attach to a single ingress to access it.
To check whether your deployment is working fine, you can do this application deployment to your EKS cluster as well.
Let’s deploy this sample game and verify that the AWS Load Balancer Controller creates an ALB Ingress resource, run the following commands:
kubectl create ns game
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.4.4/docs/examples/2048/2048_full.yaml -n game
After a few minutes, verify that the Ingress resource was created by running the following command:
kubectl get ingress -n game
Output;
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-2048 <none> * k8s-game2048-ingress2-xxxxxxxxxx-yyyyyyyyyy.us-east-2.elb.amazonaws.com 80 2m32s
Ref: https://docs.aws.amazon.com/eks/latest/userguide/alb-ingress.html
In summary, the ALB controller connects to Kubernetes by monitoring for Ingress resources, and it automatically creates and updates Application Load Balancers (ALBs) to match the routing rules defined in the Ingresses.
If you have any questions; please drop them in the comments section.