The AWS ALB Ingress Controller has been rebranded to AWS Load Balancer Controller.
“AWS Load Balancer Controller” is a controller to help manage Elastic Load Balancers for a Kubernetes cluster.
Ingress
resources by provisioning Application Load Balancers.Service
resources by provisioning Network Load Balancers.We will use Helm to install the ALB Ingress Controller.
Check to see if helm
is installed:
helm version
If Helm
is not found, see installing helm for instructions.
First, we will have to set up an OIDC provider with the cluster.
This step is required to give IAM permissions to a Fargate pod running in the cluster using the IAM for Service Accounts feature.
Learn more about IAM Roles for Service Accounts in the Amazon EKS documentation.
eksctl utils associate-iam-oidc-provider \
--region ${AWS_REGION} \
--cluster eksworkshop-eksctl \
--approve
The next step is to create the IAM policy that will be used by the AWS Load Balancer Controller.
This policy will be later associated to the Kubernetes Service Account and will allow the controller pods to create and manage the ELB’s resources in your AWS account for you.
cd ~/environment
curl -o iam_policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/main/docs/install/iam_policy.json
aws iam create-policy \
--policy-name AWSLoadBalancerControllerIAMPolicy \
--policy-document file://iam_policy.json
Next, create a Kubernetes Service Account by executing the following command
export ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account)
eksctl create iamserviceaccount \
--cluster eksworkshop-eksctl \
--namespace kube-system \
--name aws-load-balancer-controller \
--attach-policy-arn arn:aws:iam::${ACCOUNT_ID}:policy/AWSLoadBalancerControllerIAMPolicy \
--override-existing-serviceaccounts \
--approve
OR use awscli to attach the IAM policy to an existing role
aws iam attach-role-policy \
--policy-arn arn:aws:iam::${ACCOUNT_ID}:policy/AWSLoadBalancerControllerIAMPolicy \
--role-name role-name
The above command deploys a CloudFormation template that creates an IAM role and attaches the IAM policy to it.
The IAM role gets associated with a Kubernetes Service Account. You can see details of the service account created with the following command.
kubectl get sa aws-load-balancer-controller -n kube-system -o yaml
Output
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v1.6.0/cert-manager.yaml
Download the manifest
curl -Lo ingress-controller.yaml https://github.com/kubernetes-sigs/aws-load-balancer-controller/releases/download/v2.4.4/v2_4_4_full.yaml
Edit the cluster-name:
spec:
containers:
- args:
- --cluster-name=eksworkshop-eksctl
- --ingress-class=alb
Update the ServiceAccount spec to add annotations:
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/name: aws-load-balancer-controller
annotations: # Add the annotations line
eks.amazonaws.com/role-arn: arn:aws:iam::111122223333:role/role-name # Add the IAM role
name: aws-load-balancer-controller
namespace: kube-system
Note: Replace 111122223333 with your AWS account ID and role-name with your IAM role name.
Deploy AWS Load Balancer Controller
kubectl apply -f ingress-controller.yaml
kubectl apply -k github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master
Fist, We will verify if the AWS Load Balancer Controller version has been set
if [ ! -x ${LBC_VERSION} ]
then
tput setaf 2; echo '${LBC_VERSION} has been set.'
else
tput setaf 1;echo '${LBC_VERSION} has NOT been set.'
fi
If the result is ${LBC_VERSION} has NOT been set., click here for the instructions.
helm repo add eks https://aws.github.io/eks-charts
export VPC_ID=$(aws eks describe-cluster \
--name eksworkshop-eksctl \
--query "cluster.resourcesVpcConfig.vpcId" \
--output text)
helm upgrade -i aws-load-balancer-controller \
eks/aws-load-balancer-controller \
-n kube-system \
--set clusterName=eksworkshop-eksctl \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controller \
--set image.tag="${LBC_VERSION}" \
--set region=${AWS_REGION} \
--set vpcId=${VPC_ID}
You can check if the deployment
has completed
kubectl -n kube-system rollout status deployment aws-load-balancer-controller