Kubernetes: access a service in another namespace
Codemia Knowledge Hub ·
To reach a service in another namespace, use its namespace-qualified DNS name, such as database-service.backend or database-service.backend.svc.cluster.local. Service names are namespaced, but the services themselves are reachable from any namespace as long as DNS, routing and network policy allow it. Short names do not resolve across namespaces.
Use the service name with the target namespace
Inside the same namespace, a pod can usually reach a service by its short name. Across namespaces, add the namespace:
Kubernetes DNS expands this to the fully qualified service name. The explicit fully qualified form is:
Both point to the service database-service in the backend namespace.
Test it from a pod
Run a temporary pod and resolve the name:
If DNS works, the name resolves to the ClusterIP. Then test the actual port with a tool available in the image, such as wget, nc or curl:
The protocol depends on the service, but the naming pattern is the same.
What does not cross namespaces automatically
Two common assumptions are wrong:
- short service names do not resolve across namespaces
- service environment variables are not a reliable cross-namespace discovery mechanism
DNS is the standard answer. It is explicit and works across namespaces without custom discovery logic.
Network policies can still block access
Name resolution does not guarantee connectivity. With network policies enabled, the destination namespace may block ingress from the source namespace:
A policy like this is often the real reason a cross-namespace service "does not work" even though DNS resolves. Also confirm that the destination service listens on the expected port and protocol.
You do not need an external service type
NodePort, LoadBalancer or an Ingress are not needed to connect between namespaces inside the cluster. A normal ClusterIP service is the right type for in-cluster, cross-namespace traffic. Exposing an internal dependency externally is a common design mistake; keep service-to-service traffic internal unless you have a real external access requirement.
Put the qualified hostname in config
If an application in frontend depends on a service in backend, write the dependency explicitly:
This makes the dependency visible and avoids ambiguity if another namespace later defines a service with the same short name.
Related reading
- kubernetes How to deattach from an attached pod
- Kubernetes how to debug CrashLoopBackOff
- Kubernetes How to delete PODs based on age/creation time
- Kubernetes How to ensure one pod gets scheduled on each worker node?
- Kubernetes how to load balance EXTERNAL persistent tcp connections?
- Kubernetes how to make Deployment to update image
- Kubernetes How to pass pipe character in readiness probe command
- Kubernetes How to refer to one environment variable from another?
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a GPU Cluster Scheduler for ML Training: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.