This limitation can be frustrating for developers who want to leverage ALB’s advanced capabilities. The main challenge, then, is how to integrate the superior ALB with an Ingress controller like Nginx on EKS to fully benefit from ALB’s security and performance features. In this post, we will explore how to overcome this challenge by deploying Ingress Nginx with ALB Controller on an EKS cluster.
Before starting with AWS Load Balancer Controller, make sure the following components are set up:
kube-proxy
, and CoreDNS add-ons are at the minimum versions listed in Cluster add-ons.Upon completion of the prerequisites – such as AWS CLI installation and EKS cluster – the next task involves creating and attaching an IAM policy to the EKS node role. This action enables the AWS Load Balancer Controller to interact with AWS APIs and manage Application Load Balancers.
Create an IAM policy:
To allow the AWS Load Balancer Controller to interact with AWS APIs, we first need to create and attach an IAM policy to your EKS node role.
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.7.2/docs/install/iam_policy.json
aws iam create-policy \
--policy-name AWSLoadBalancerControllerIAMPolicy \
--policy-document file://iam_policy.json
The AWS Load Balancer Controller needs to identify which subnets to use when creating ALBs. To ensure this, tag the subnets with the appropriate key-value pairs.
for NODEGROUP in $(aws eks list-nodegroups --cluster-name "${CLUSTER_NAME}" --query 'nodegroups' --output text); do
aws ec2 create-tags \
--tags "Key=kubernetes.io/role/elb,Value=1" \
--resources $(aws eks describe-nodegroup --cluster-name "${CLUSTER_NAME}" \
--nodegroup-name "${NODEGROUP}" --query 'nodegroup.subnets' --output text )
done
aws ec2 describe-subnets --filters "Name=tag:kubernetes.io/role/elb,Values=1"
helm repo add eks https://aws.github.io/eks-charts
helm install [RELEASE_NAME] eks/aws-load-balancer-controller \
--namespace alb \
--set clusterName=clusterName \
--set serviceAccount.name=sa-name \
--set ingressClass=ingressClass-name
--set region=region-code \
--set vpcId=vpc-xxxxxxxx
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm install [RELEASE_NAME] ingress-nginx/ingress-nginx \
--set controller.service.type=NodePort
With both controllers (AWS Load Balancer Controller and Ingress NGINX Controller) installed, you can now create an Ingress resource to configure an ALB with your desired settings. Ensure that the Ingress backend points to the Ingress NGINX service. Since the service type is set to NodePort, the ALB will forward traffic seamlessly to the NGINX service running on the node.
Below is an example Ingress YAML file that sets up an ALB with custom configurations:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
alb.ingress.kubernetes.io/load-balancer-attributes: deletion_protection.enabled=true
alb.ingress.kubernetes.io/load-balancer-name: alb-with-ingress-nginx #Alb name
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/security-groups: sg-id #custom security-group ID
alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-TLS13-1-2-2021-06
alb.ingress.kubernetes.io/ssl-redirect: "443"
alb.ingress.kubernetes.io/success-codes: 200,404
alb.ingress.kubernetes.io/target-type: instance
alb.ingress.kubernetes.io/wafv2-acl-arn: arn:aws:wafv2:region:account-id:regional/webacl/waf-name/id #AWS WAF ARN
name: ingress-nginx
namespace: kube-system
spec:
ingressClassName: alb
rules:
- host: 'example.com'
http:
paths:
- backend:
service:
name: ingress-nginx-controller #Ingress-nginx service name
port:
number: 80
path: /
pathType: Prefix
By following these steps, you can successfully integrate Ingress NGINX with an ALB using AWS Load Balancer Controller. This setup allows you to benefit from the advanced load balancing features of ALB while maintaining the flexibility of Ingress NGINX for routing and traffic management.