TCP ingress support in Kubernetes
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Kubernetes Ingress resources are defined for HTTP and HTTPS routing, so pure TCP exposure requires controller-specific extensions. Many teams discover this when they need to publish databases, message brokers, or custom binary protocols. A stable setup depends on choosing the right controller feature, mapping ports carefully, and validating network policy boundaries.
Core Topic Sections
HTTP Ingress versus TCP forwarding
Native Kubernetes Ingress focuses on Layer 7 routing rules such as host and path. TCP services operate at Layer 4, where packets are forwarded by port instead of HTTP semantics. Because of this, TCP is usually configured through the ingress controller itself, not the standard Ingress object.
A common pattern with NGINX Ingress Controller is a dedicated ConfigMap that maps external ports to backend services.
Example with NGINX Ingress Controller
Create a ConfigMap that maps port 9000 on the ingress controller to a service in your namespace.
Then ensure the ingress controller deployment references that map and exposes the port on its Service.
Controller documentation for your installed version should be the source of truth for exact flags and chart values.
Backend service and pod readiness
Expose your TCP application as a regular ClusterIP service. Readiness probes are still important so the controller forwards only to healthy pods.
If readiness is missing or too permissive, you may see intermittent connection resets under rollout conditions.
Test end-to-end connectivity
After applying manifests, validate from outside and inside the cluster.
Testing both paths isolates whether failures are in service routing, external load balancer configuration, or pod-level listeners.
Security and policy controls
Exposing TCP ports can broaden attack surface quickly. Lock down access with security groups, firewall rules, and Kubernetes NetworkPolicy where supported. If traffic contains sensitive data, enforce TLS at the application layer or terminate TLS where your protocol allows.
Also document ownership per exposed port. Port mapping drift becomes difficult to audit when multiple teams share one ingress controller.
Alternatives to TCP ingress extension
For some workloads, a dedicated Service of type LoadBalancer is simpler and clearer than controller-level TCP maps. This is often better when a single service needs direct exposure and no shared ingress behavior. Gateway API implementations can also provide cleaner multi-protocol routing in modern clusters.
Common Pitfalls
- Expecting standard
Ingressresources to route raw TCP without controller-specific configuration. - Forgetting to expose the mapped TCP port on the ingress controller Service.
- Mapping to the wrong namespace or service name in the TCP
ConfigMap. - Skipping readiness checks, which causes transient resets during rollouts.
- Opening external TCP ports without network policy, firewall, or ownership controls.
Summary
- Kubernetes HTTP Ingress does not directly cover generic TCP forwarding.
- Use ingress-controller TCP extension features or a dedicated LoadBalancer service.
- Keep TCP port maps, controller service ports, and backend service ports consistent.
- Validate connectivity from both external and in-cluster paths.
- Treat exposed TCP ports as security-sensitive infrastructure with explicit policy.
Related reading
- telepresence error connector.Connect kubeconfig has no context definition
- Terminate istio sidecar istio-proxy for a kubernetes job / cronjob
- Terraform and Helm3 Error Kubernetes cluster unreachable
- Terraform AWS Kubernetes EKS resources with ALB Ingress Controller won't create load balancer
- Tensor flow serving docker invalid field
- TensorFlow in nvidia-docker failed call to cuInit CUDA_ERROR_UNKNOWN
- TCPClient vs Socket in C
- TcpClient vs Socket when dealing with asynchronousy

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.