![]() |
VOOZH | about |
If you're running applications on Kubernetes using Amazon EKS (Elastic Kubernetes Service), you need a way to efficiently distribute traffic across your services. The AWS Application Load Balancer Controller makes this process much easier by automatically managing the distribution of traffic to your applications, helping you scale seamlessly and ensure high availability.
This guide will walk you through the process of setting up and deploying the ALB Ingress Controller on your Kubernetes cluster. Whether you're new to Kubernetes or looking to optimize your cloud setup, this article will help you get started quickly and effectively.
The AWS ALB Controller is a tool that helps Kubernetes clusters automatically manage AWS Application Load Balancers (ALBs). It acts as an Ingress Controller, meaning it helps route external traffic into your Kubernetes cluster based on defined rules.
Why is this important? When you have multiple services running in Kubernetes, you need a way to efficiently route traffic between them. The AWS ALB Controller automates that by configuring the ALB for you, saving time and ensuring your traffic flows smoothly.
Setting up an Application Load Balancer (ALB) in Kubernetes is key to distributing traffic evenly across your services, improving performance, and maintaining high availability. If you're using Amazon EKS (Elastic Kubernetes Service), the AWS ALB Ingress Controller makes this process much simpler.
Here’s a straightforward guide to setting up and deploying the AWS ALB Ingress Controller in your Kubernetes cluster.
Before starting, ensure that you have the following:
The AWS Load Balancer Controller is installed via Helm, a tool for managing Kubernetes applications. Here’s how you can install it:
First, add the official AWS Helm repository to your setup:
helm repo add eks https://aws.github.io/eks-charts/
helm repo update
Once the repository is added, you can install the AWS Load Balancer Controller with this command:
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
--set clusterName=<your-cluster-name> \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controller \
--namespace kube-system
Make sure to replace <your-cluster-name> with your actual EKS cluster name. This command installs the ALB Ingress Controller into the kube-system namespace, and uses an existing service account (which we will create in the next step).
To allow the AWS Load Balancer Controller to interact with AWS resources like load balancers and security groups, you need to create an IAM policy and attach it to a service account.
Start by creating an IAM policy with the required permissions:
aws iam create-policy \
--policy-name AWSLoadBalancerControllerIAMPolicy \
--policy-document file://iam-policy.json
Here’s an example iam-policy.json file with the required permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"elasticloadbalancing:*",
"ec2:Describe*",
"ec2:AuthorizeSecurityGroupIngress",
"ec2:CreateSecurityGroup",
"ec2:DeleteSecurityGroup"
],
"Resource": "*"
}
]
}
Once the policy is created, attach it to an IAM role using the following command:
eksctl create iamserviceaccount \
--region <region> \
--name aws-load-balancer-controller \
--namespace kube-system \
--cluster <your-cluster-name> \
--attach-policy-arn arn:aws:iam::<account-id>:policy/AWSLoadBalancerControllerIAMPolicy \
--approve \
--override-existing-serviceaccounts
Replace <region>, <your-cluster-name>, and <account-id> with your actual values.
Now that the controller is installed, the next step is to define the routing rules for your Application Load Balancer using an Ingress resource.
Here’s an example YAML file for creating an Ingress resource. This defines how the ALB should route traffic to your service:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
namespace: default
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]'
alb.ingress.kubernetes.io/backend-protocol: HTTP
spec:
rules:
- host: <your-domain>.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: <your-service-name>
port:
number: 80
In this example, replace <your-domain> with your domain name and <your-service-name> with the name of the service you want to expose.
Once you’ve created the YAML file, apply it to your Kubernetes cluster:
kubectl apply -f example-ingress.yamlAfter applying the Ingress resource, verify the status of the ALB by running:
kubectl get ingressYou should see the external DNS name of the ALB in the output. If everything is set up correctly, the ALB will be managing traffic to your backend service.
To test, navigate to your domain in a browser. The ALB should route the traffic to your backend service, and the load will be distributed across your Kubernetes pods. If you see the expected result, then the setup is working correctly.
Congratulations, you’ve successfully set up and deployed the AWS Application Load Balancer Controller in your Kubernetes cluster. With this setup, you can now manage and distribute external traffic efficiently across your services, ensuring better scalability, high availability, and a smooth user experience.