How to use a single Loadbalancer for multiple ingresses in EKS, using Terraform.

Infrastructure Developer
Search for a command to run...

Infrastructure Developer
No comments yet. Be the first to comment.
Prerequisite Install AWS Load Balancer Controller: This controller is essential for managing AWS load balancers in a Kubernetes environment. Step 1: Enable Proxy Protocol in NLB Target Group Add the following annotation to your NLB Target Group to...

AWS Managed NAT Gateway is a widely-used service that provides seamless internet access for resources within a private VPC subnet. However, its cost structure has been a pain point for many AWS users, with high fees for both hourly usage and data pro...
Configure NTP in timesyncd.conf echo "NTP=169.254.169.123" | sudo tee -a /etc/systemd/timesyncd.conf cat /etc/systemd/timesyncd.conf Enable the timesyncd.service sudo systemctl unmask systemd-timesyncd.service sudo apt install systemd-timesyncd ...

Error waiting to create Instance: Error waiting for Creating Instance: Error code 7, message: Required 'compute.subnetworks.use' permission for

automating time tracking for a more accurate record of time spent on projects

In Cloud, creating resources always comes with a cost. So operating a huge Kubernetes cluster with many deployments and ingresses usually would need a lot of load balancers.
Conceptually Kubernetes ingress is like a cloud load balancer, so it's a lot simpler to treat & configure it like one.
In this post, I'll illustrate using one load balancer for multiple ingresses.
At this point, I have an EKS cluster deployed by Terraform, and an AWS load balancer controller installed.
The key is using IngressGroup feature.
alb.ingress.kubernetes.io/group.name: my-team.awesome-group
Specify the order of ingresses by using:
alb.ingress.kubernetes.io/group.order: '10'
Below is complete code snippet in Terraform.
First Ingress
resource "kubernetes_ingress_v1" "testing" {
metadata {
name = "testing"
annotations = {
"alb.ingress.kubernetes.io/group.name" = "default"
"alb.ingress.kubernetes.io/group.order" = "10"
"alb.ingress.kubernetes.io/ssl-redirect" = "443"
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"alb.ingress.kubernetes.io/success-codes" = "200,404,301,302"
"alb.ingress.kubernetes.io/listen-ports" = "[{\"HTTPS\":443}, {\"HTTP\":80}]"
"alb.ingress.kubernetes.io/certificate-arn" = "arn:aws:acm:ap-southeast-1:"
}
namespace = "testing"
}
spec {
ingress_class_name = "alb"
rule {
host = "testing.ujangmumu.com"
http {
path {
backend {
service {
name = "testing"
port {
number = 80
}
}
}
path = "/*"
}
}
}
}
depends_on = [module.alb-ingress]
}
Second Ingress
resource "kubernetes_ingress_v1" "example" {
metadata {
name = "example"
annotations = {
"alb.ingress.kubernetes.io/group.name" = "default"
"alb.ingress.kubernetes.io/group.order" = "20"
"alb.ingress.kubernetes.io/ssl-redirect" = "443"
"alb.ingress.kubernetes.io/scheme" = "internet-facing"
"alb.ingress.kubernetes.io/success-codes" = "200,404,301,302"
"alb.ingress.kubernetes.io/listen-ports" = "[{\"HTTPS\":443}, {\"HTTP\":80}]"
"alb.ingress.kubernetes.io/certificate-arn" = "arn:aws:acm:ap-southeast-1:"
}
namespace = "example"
}
spec {
ingress_class_name = "alb"
rule {
host = "example.ujangmumu.com"
http {
path {
backend {
service {
name = "example"
port {
number = 80
}
}
}
path = "/*"
}
}
}
}
depends_on = [module.alb-ingress]
}