Ingress controller to route TCP traffic
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Ingress controllers in Kubernetes are essential components that manage external access to services within a cluster. While they primarily handle HTTP and HTTPS traffic, an Ingress controller can also be configured to route TCP traffic. This allows non-HTTP applications to benefit from Kubernetes' traffic management features, such as load balancing and virtual hosting.
Understanding Ingress Controllers
An Ingress controller is a specialized load balancer that acts as a reverse proxy, managing incoming traffic into a Kubernetes cluster. It interprets the Ingress resource configurations defined by the user to decide how to route external requests to internal services.
How Ingress Controllers Operate
- Configuration: The Ingress resource specifies rules about how traffic should be routed to different services in the cluster based on hostnames or paths.
- Routing: The Ingress controller watches the Kubernetes API server for changes to Ingress resources and configures itself to route traffic accordingly.
- Types of Controllers: Popular Ingress controllers include NGINX, Traefik, and HAProxy.
Routing TCP Traffic
Routing TCP traffic involves configuring the Ingress controller to allow non-HTTP traffic to reach the services. This scenario is vital for applications like databases or services that listen on custom ports.
Steps to Configure TCP Routing
- Choose an Ingress Controller: Not all Ingress controllers support TCP routing. For this article, let's focus on the NGINX Ingress controller, which provides a TCP feature through a ConfigMap.
- Prepare the ConfigMap:
- Create a `ConfigMap` that defines the mapping of external ports to internal services.
- This ConfigMap must be referenced via command-line arguments or container options.
- Deploy the Ingress Controller:
- Deploy the NGINX Ingress controller, ensuring the TCP ConfigMap is correctly referenced.
- Configure the Services:
- Ensure that the necessary services are defined in Kubernetes with appropriate ports exposed for listening.
- Update Firewall Rules:
- Ensure that the cluster's firewall settings allow incoming connections on the desired TCP ports.
Example Configuration
Suppose we have a database service running on port 5432 within the cluster, and we want to expose it on port 30000.
- --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
- Security: Always secure TCP services with network policies and encrypt traffic where possible.
- Performance: Monitor load and performance using tools such as Prometheus to ensure that the Ingress controller can handle the expected throughput.
- Scalability: Use horizontal pod autoscaling to manage load spikes and maintain high availability.
Related reading
- Ingress controller vs api gateway
- Ingress not working in google kubernetes engine for multiple services Spring Boot
- Ingress routing rules to access prometheus server
- Ingress vs Load Balancer
- InitContainer not idempotent, how to prevent it from running twice?
- Inject code/files directly into a container in Kubernetes on Google Cloud Engine
- Initial setup of terraform backend using terraform
- Injecting Env variable from initContainer to the main container before its ENTRYPOINT starts

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.