Skip to content
Shakthivel Arumugam

Let Terraform own the ALB, and bind Kubernetes services to it

In Adhesive, an open-source Glue replacement on EKS, the load balancer is a Terraform resource and services attach with TargetGroupBinding. Here is why, and what it costs.

22 November 2026, 4 min read

  • Terraform
  • AWS
  • EKS
  • Kubernetes
  • ALB

Adhesive puts eight web UIs behind one Application Load Balancer: Grafana, Prometheus, Alertmanager, Kibana, Airflow, the Spark History Server, Kafka UI and OpenMetadata. The usual way to do this on EKS is one Ingress per service and let the AWS Load Balancer Controller create the ALB. I did not do that. Terraform owns the ALB, and the cluster only attaches services to it. This post explains the two problems that pushed me there.

The two problems with controller-created load balancers

The hostname arrives too late. Each UI is served under a path, such as /grafana or /airflow, so each one needs its base URL configured. If the controller creates the ALB, its hostname does not exist until after the first apply. Every Helm release that needs the URL then waits for a second apply.

Teardown can get stuck. A load balancer the controller created is not in Terraform state. If it is still alive when terraform destroy tries to delete the VPC, the destroy fails on dependent network interfaces and security groups, and you clean up by hand. Adhesive is meant to be brought up for a session and torn down the same day, with nothing left billing, so this mattered.

The shape of the fix

One locals block is the routing table. Each app has a port, a health-check path, a listener-rule priority and a path:

locals {
  apps = {
    grafana    = { port = 3000, health = "/grafana/api/health", priority = 10, path = "/grafana" }
    prometheus = { port = 9090, health = "/prometheus/-/ready", priority = 20, path = "/prometheus" }
    airflow    = { port = 8080, health = "/airflow/api/v2/monitor/health", priority = 50, path = "/airflow" }
    # ...
    openmetadata = { port = 8585, health = "/", priority = null, path = null }
  }
}

Terraform creates the ALB, one target group per app with for_each, and a listener rule for every app that has a priority. An app without a priority, here OpenMetadata, is served by the listener's default action, so it sits at /.

Because the ALB is a Terraform resource, its DNS name is known at plan time. Each UI's base URL can be passed straight into its Helm values in the same apply.

Attaching a service

Inside the cluster, a TargetGroupBinding connects an existing Service to the Terraform-created target group:

apiVersion: elbv2.k8s.aws/v1beta1
kind: TargetGroupBinding
metadata:
  name: ${name}
  namespace: ${namespace}
spec:
  serviceRef:
    name: ${service}
    port: ${port}
  targetGroupARN: ${target_group_arn}
  targetType: ip

The AWS Load Balancer Controller still runs, but only to register pod IPs in the target group as pods come and go. It never creates or deletes a load balancer. With targetType: ip, the ALB sends traffic straight to pods.

Security groups in one place

The bindings leave out the networking field on purpose, so the controller does not manage security groups. Instead, Terraform holds the only rules that let traffic in:

  • The ALB's security group accepts HTTP from the CIDRs in allowed_cidrs, and nothing else.
  • The node security group accepts each app port from the ALB's security group only. The ports come from the same locals block, deduplicated, so Grafana and Kibana ports are open to the ALB and nothing wider.

The result is that "who can reach what" is readable in one file, and it does not depend on what a controller decides to do.

What it costs

  • Routing lives in Terraform. Adding a UI means adding an entry to the apps map and a binding, not writing an Ingress. For a platform with a fixed set of eight UIs, I accept that. For a cluster where teams ship services often, an Ingress per team would be the better fit.
  • Two systems have to agree on names. The target group ARN is the contract between Terraform and the binding. It is passed in as a template variable, which works, but a typo shows up as an unhealthy target and not as a plan error.
  • No HTTPS yet. The listener is HTTP only, restricted by CIDR. ACM, a custom domain and SSO are the first items on my next-steps list.

Check that it worked

The smoke test in the repository, scripts/smoke-test.sh, requests every ALB path and checks target group health. After a full teardown, scripts/cost-check.sh lists any billable resource that survived, and it reported nothing. That second result is the one that justified the design, since a leftover load balancer was the failure I was trying to avoid.