Skip to main content

Setting up the AWS Application Load Balancer Controller (LBC) on the EKS Cluster

Objective

This lab shows you how to set up the AWS Load Balancer Controller (LBC) on your cluster, which enables the routing of external traffic to your Kubernetes services. We'll leverage the IAM Roles for Service Accounts (IRSA) we configured when we created our cluster, ensuring that the controller has the required permissions.

info

Classic Load Balancers are not supported for pods running on Fargate. Network Load Balancers are only supported when using the AWS Load Balancer Controller and IP target type mode.

Prerequisites

Initial Setup

Navigate to the root directory of the python-fastapi-demo-docker project where your environment variables are sourced:

cd ~/environment/python-fastapi-demo-docker

1. Set Environment Variables

Before we start setting up our EKS cluster, we need to set a couple environment variables.

Export the name of your EKS cluster and the VPC ID associated with your EKS cluster executing the following commands:

export CLUSTER_VPC=$(aws eks describe-cluster --name fargate-quickstart --region ${AWS_REGION} --query "cluster.resourcesVpcConfig.vpcId" --output text)
export CLUSTER_NAME=fargate-quickstart

2. Verify the Service Account

First, we need to make sure the "aws-load-balancer-controller" service account is correctly set up in the "kube-system" namespace in our cluster.

Run the following command:

kubectl get sa aws-load-balancer-controller -n kube-system -o yaml

The expected output should look like this:

apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::012345678901:role/eksctl-fargate-quickstart-addon-iamserviceac-Role1-J2T54L9SG5L0
creationTimestamp: "2023-05-30T23:09:32Z"
labels:
app.kubernetes.io/managed-by: eksctl
name: aws-load-balancer-controller
namespace: kube-system
resourceVersion: "2102"
uid: 2086b1c0-de23-4386-ae20-19d51b7db4a1

3. Add and Update EKS chart repository to Helm:

Add the EKS chart repository to Helm:

helm repo add eks https://aws.github.io/eks-charts

Update the repositories to ensure Helm is aware of the latest versions of the charts:

helm repo update

4. Deploy the Load Balancer Controller

To install the AWS Load Balancer Controller in the "kube-system" namespace of the EKS cluster, run the following Helm command, replacing region with your specific region:

note

If the below command fails with an error similar to Error: INSTALLATION FAILED: cannot re-use a name that is still in use, it means the AWS Load Balancer Controller is already installed. In this case, replace helm install with helm upgrade -i in the below command to ensure the latest version of the controller and Helm Chart.

helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
--set clusterName=${CLUSTER_NAME} \
--set serviceAccount.create=false \
--set region=${AWS_REGION} \
--set vpcId=${CLUSTER_VPC} \
--set serviceAccount.name=aws-load-balancer-controller \
-n kube-system

You should receive an output confirming the successful installation of the AWS Load Balancer Controller (LBC):

NAME: aws-load-balancer-controller
LAST DEPLOYED: Sat May 11 01:21:04 2023
NAMESPACE: kube-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
AWS Load Balancer controller installed!

To list installed helm releases run the following

helm list -A

You should receive simillar output:

NAME                        	NAMESPACE  	REVISION	UPDATED                             	STATUS  	CHART                             	APP VERSION
aws-load-balancer-controller kube-system 1 2023-09-11 00:31:57.585623 -0400 EDT deployed aws-load-balancer-controller-1.6.0 v2.6.0