Blog
Simplifying Kubernetes Ingress with ALB Ingress ControllerPosted by
Abhay Bahadauria on 07 Aug 2023
As Kubernetes gains popularity as the go-to container orchestration platform, managing traffic and load balancing for applications running on Kubernetes clusters becomes crucial. Kubernetes Ingress provides a convenient way to expose services to external users, but it lacks advanced routing capabilities and native integration with cloud provider load balancers; This is where the Application Load Balancer (ALB) Ingress Controller comes into play.
This technical blog will explore the ALB Ingress Controller, its benefits, and how it simplifies the management of Kubernetes Ingress resources. You will dive into its architecture, deployment considerations, and configuration options. By the end of this blog, you will have a solid understanding of how to leverage the ALB Ingress Controller to streamline Kubernetes application traffic management.
Table of Contents
Before diving into the ALB Ingress Controller, let’s briefly understand the concept of Kubernetes Ingress. Kubernetes Ingress is an API object that provides an entry point for external traffic to access services within a Kubernetes cluster. It acts as a layer 7 (application layer) load balancer, routing incoming requests to the appropriate services based on rules and configurations.
In a Kubernetes cluster, services are typically accessed through a Service object, which is a stable endpoint for internal communication. However, by default, services are not directly accessible outside the cluster; This is where the Ingress resource comes into play, providing an external access point and allowing traffic to be routed to different services based on various criteria.
Overall, Kubernetes Ingress simplifies the management of external access to services within a cluster by providing a declarative way to define and manage routing rules. It allows for flexible and granular traffic routing, load balancing, and SSL termination, along with enabling the integration of external services with the Kubernetes ecosystem.
The ALB Ingress Controller is a Kubernetes controller that manages AWS ALB resources and integrates them with Kubernetes Ingress. It replaces the default Ingress controller in Kubernetes and provides enhanced functionality, including advanced routing, SSL termination, and integration with AWS services. It leverages the AWS Application Load Balancer, a highly available and scalable load-balancing solution.
The ALB Ingress Controller is a component in the Kubernetes ecosystem that enables the use of Application Load Balancers (ALBs) as ingress resources for the applications. In Kubernetes, an ingress is a collection of rules that define how incoming traffic should be routed to services within the cluster.
The ALB Ingress Controller specifically integrates with Amazon Web Services (AWS) Elastic Load Balancer (ELB) service, allowing you to leverage the advanced features and capabilities of ALBs for routing and load balancing traffic to Kubernetes services.
The ALB Ingress Controller offers several benefits over the default Ingress controller:
Overall, the ALB Ingress Controller simplifies exposing Kubernetes applications to external traffic by leveraging the power of ALBs. Also, it provides advanced routing capabilities, scalability, and high availability while reducing the operational complexity of managing load balancers manually.
The ALB Ingress Controller architecture consists of several components, including the Ingress Controller pod, the Target Group Binding controller, and the AWS ALB Ingress Controller. Basically, this section will provide you an in-depth explanation of each component and their interactions.
Overall, the ALB Ingress Controller bridges the gap between Kubernetes Ingress resources and AWS ALB, providing seamless integration for routing traffic to Kubernetes services using ALB’s advanced load balancing features.
Basically, this section will guide you through the process of deploying the ALB Ingress Controller in your Kubernetes cluster. As well as, it will cover installation methods, prerequisites, and configuration options for different deployment scenarios. In addition, you are deploying the ALB Ingress Controller using Helm.
Prerequisites
$ eksctl utils associate-iam-oidc-provider --region --cluster --approve
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.4.4/docs/install/iam_policy.json
iam_policy.json
aws iam create-policy \
--policy-name LoadBalancerControllerIAMPolicy \
--policy-document file://iam_policy.json
That we use in creating policy for the role; you are attaching on AWS EKS Load Balancer Controller role.
Using the AWS CLI and kubectl
oidc_id=$(aws eks describe-cluster --name --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
aws iam list-open-id-connect-providers | grep $oidc_id | cut -d "/" -f4
cat >aws-load-balancer-role-trust-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated":"arn:aws:iam:::oidc-provider/oidc.eks..amazonaws.com/id/"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks..amazonaws.com/id/:aud": "sts.amazonaws.com",
"oidc.eks..amazonaws.com/id/:sub": "system:serviceaccount:kube-system:aws-load-balancer-controller"
}
}
}
}
}
EOF
aws iam create-role \
--role-name EKSLoadBalancerControllerRole \
--assume-role-policy-document file://"aws-load-balancer-role-trust-policy.json"
aws iam attach-role-policy \
--policy-arn arn:aws:iam::11xxxxxx33:policy/LoadBalancerControllerIAMPolicy \
--role-name EKSLoadBalancerControllerRole
cat >aws-load-balancer-controller-service-account.yaml <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/name: aws-load-balancer-controller
name: aws-load-balancer-controller
namespace: kube-system
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam:::role/EKSLoadBalancerControllerRole
EOF
kubectl apply -f aws-load-balancer-controller-service-account.yaml
helm repo add eks https://aws.github.io/eks-charts
helm repo update
602401143452.dkr.ecr..amazonaws.com/amazon/aws-load-balancer-controller:v2.4.4
--set image.repository=602401143452.dkr.ecr..amazonaws.com/amazon/aws-load-balancer-controller
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
-n kube-system \
--set clusterName=my-eks-cluster \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controller
--set
image.repository=602401143452.dkr.ecr..amazonaws.com/amazon/aws-load-balancer-controller
For instance, you are using the following command:
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
-n kube-system \
--set clusterName=dev-eks-cluster \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controller \
--set image.repository=602401143452.dkr.ecr.us-east-1.amazonaws.com/amazon/aws-load-balancer-controller
You can verify using the below command that the controller is deployed successfully
kubectl get deployment -n kube-system aws-load-balancer-controller
You will get the following output
NAME READY UP-TO-DATE AVAILABLE AGE
aws-load-balancer-controller 2/2 2 2 80s
To uninstall the ALB ingress controller, use the following command
helm list -n kube-system
helm uninstall -n kube-system
After deploying the ALB Ingress Controller, you must configure and manage Ingress resources to define routing rules and expose services. Also, this section will help you understand how to create and manage Ingress resources, including various annotations and configuration options.
Create an Ingress Resource: Basically, define an Ingress resource in Kubernetes to configure the routing rules for your applications. As well as, an Ingress resource specifies the hostnames, paths, and back-end services to route incoming traffic. Here’s an example of an Ingress resource.
YAML:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/load-balancer-name: non-prod-alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/subnets: subnet-1,subnet-2
alb.ingress.kubernetes.io/security-groups: sg-example
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]'
alb.ingress.kubernetes.io/ssl-redirect: '443'
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
The ALB Ingress Controller provides advanced routing capabilities, such as host-based routing, path-based routing, URL rewrites, and redirect rules.
For example:
Path-based routing:
spec:
rules:
- host: example.com
http:
paths:
- path: /service-1
pathType: Prefix
backend:
service:
name: service-1
port:
number: 80
- host: example.com
http:
paths:
- path: /service-2
pathType: Prefix
backend:
service:
name: service-2
port:
number: 80
Host-based routing:
spec:
rules:
- host: example-1.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-1
port:
number: 80
- host: example-2.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-2
port:
number: 80
Basically, one of the key advantages of the ALB Ingress Controller is its seamless integration with AWS services. Also, this section will explore how to leverage features like AWS Certificate Manager, AWS WAF, and SSL certificate management, along with monitoring your Kubernetes applications.
You can add the following annotation to configure ACM:
annotations:
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1::99999999999:certificate/69daxxx58-bxxd-xxx9-b384-d4fxxxb6
In conclusion, the ALB Ingress Controller is a powerful tool that simplifies the management of Kubernetes Ingress resources while providing advanced routing and integration capabilities with AWS services. Adopting the ALB Ingress Controller can enhance the scalability, reliability, and security of your Kubernetes applications running on AWS. As well as, you can now leverage the ALB Ingress Controller and streamline your application traffic management in Kubernetes with the knowledge from this blog.
In addition, by implementing the ALB Ingress Controller, you can take full advantage of the powerful features and seamless integration provided by AWS, ensuring a smooth and efficient traffic management experience for your Kubernetes applications.
Gophers Lab specializes in DevOps Automation Services with one of the best DevOps Team which has deep expertise on all major cloud platforms, such as AWS, GCP, and Azure. You can contact us to outsource DevOps projects or hire dedicated DevOps engineers.
REFERENCES:
ALB ingress controller:
https://docs.aws.amazon.com/eks/latest/userguide/aws-load-balancer-controller.html
AWS CLI:
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
HELM:
https://docs.aws.amazon.com/eks/latest/userguide/helm.html
KUBECTL:
https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html
Share On
Tags
ALB Ingress Controller
AWS
Deploying ALB Ingress Controller
Kubernetes Ingress
Kubernetes Ingress with ALB Ingress Controller
Managing Ingress Resources
Highlights
Download Blog
Talk to Our Experts
Get in Touch with us for a Walkthrough