The pod kept failing, and no one knew why. Logs showed nothing. Metrics were green. But the database connection was dead. We were inside Kubernetes. The culprit was the Ingress.
Kubernetes Ingress is famous for routing HTTP and HTTPS traffic into your cluster. But database access? That’s where it gets tricky. Direct database connections often run on TCP, not HTTP, and most default Ingress controllers don’t speak TCP out of the box. This is where many teams get stalled: they assume that connecting to a database from outside Kubernetes will work the same way as a web app route. It doesn’t.
When your application code runs inside the cluster, Kubernetes Service objects make it easy to reach the database. But external clients — analysts, BI tools, migration scripts — often need to connect from outside the cluster’s network boundary. Simply opening firewall rules to a database pod is risky and brittle. You need a secure, reliable, and performant way to expose that database endpoint without breaking your cluster’s security posture.
Here’s how to do it. First, choose an Ingress controller that supports raw TCP and TLS streams. NGINX and HAProxy can be configured for this, but require extra configuration. Newer controllers like Traefik or cloud-native load balancers offer more flexibility through custom resources. You define a TCP route, point it at a Kubernetes Service tied to your database, and terminate TLS if needed. With that, external traffic flows through your Ingress layer just like HTTP — only now it’s carrying database protocol packets.