Kubernetes service discovery explained in plain terms: service discovery is how one application finds another inside a cluster, by name, at the moment it connects. It answers the question of how a web front end reaches the orders database when the database pods are constantly being replaced, with new IP addresses each time. The short answer is that Kubernetes gives every service a stable name and a stable virtual IP, and it keeps a live list of the healthy pods behind that name, so clients connect to the name and the cluster handles the rest.
Pods are deliberately disposable. A pod’s IP address changes whenever it restarts, is rescheduled or is replaced by a new version, so nothing inside a cluster should ever hard-code a pod IP. Service discovery exists to hide that churn behind names that do not change.
The mechanism is built from five layers that each do one job: labels mark pods, a Service selects them, an EndpointSlice records which are ready, kube-proxy or an eBPF dataplane routes the virtual IP, and CoreDNS resolves the name to that IP. Our guide to Kubernetes architecture explains the control plane components that keep those layers in sync.
Key takeaways
- Kubernetes service discovery explained in one line: a stable Service name maps to the current IP addresses of the healthy pods behind it.
- CoreDNS has been the default cluster DNS since Kubernetes 1.13, and it answers names such as my-svc.my-namespace.svc.cluster.local.
- EndpointSlices hold the backend addresses for a Service, capped at 100 endpoints per slice by default.
- Headless Services return pod IPs directly instead of a virtual IP, which is how StatefulSets get stable per-pod names.
- DNS reflects readiness: a pod failing its readiness probe drops out of DNS answers and EndpointSlices alike.
What service discovery has to solve
A microservices application is a set of services that call each other over the network, and each service needs to find the others without knowing where they run. In a traditional data centre that problem was solved with fixed hostnames and load balancers that rarely changed.
In Kubernetes, pods come and go in seconds, nodes are replaced, and a deployment can swap every replica of a service in a rolling update. The discovery mechanism therefore has to be dynamic: it must notice changes in the set of healthy backends and make them visible to clients almost immediately.
Kubernetes solves this by separating two jobs that are often confused. Name resolution turns a service name into an address, and that is the job of CoreDNS.
Traffic forwarding takes a connection to that address and delivers it to one healthy backend, and that is the job of the Service dataplane, usually kube-proxy. A client that cannot reach a service may have a DNS problem or a forwarding problem, and knowing which layer is responsible is the first step in fixing it. Best for: anyone debugging a service that is reachable by IP but not by name, or by name but not by IP, because the two symptoms point at different layers.
The five layers, from label to DNS answer
The chain starts with labels. A Service defines membership with a label selector, and its controller continuously scans for pods carrying those labels, updating the Service’s EndpointSlices as pods appear, disappear or change readiness.
Each Service also gets a ClusterIP, a virtual address tied to the Service’s lifespan that does not change while the Service exists. A mismatched selector leaves the Service with no endpoints, and DNS still resolves the name, but no backend ever receives traffic, which is one of the most common configuration mistakes in Kubernetes.
EndpointSlices hold the backend addresses for a Service. The control plane creates them automatically for every Service with a selector, links each slice to its Service with a label, and caps each slice at 100 endpoints by default, configurable up to 1,000, so a large Service is split across several slices.
On each node, kube-proxy watches Service and EndpointSlice changes and programs the node to capture traffic sent to the ClusterIP and redirect it to one endpoint. Newer networking setups replace kube-proxy with an eBPF dataplane, such as Cilium, which does the same job in the kernel, but the model is unchanged: the virtual IP is a stable front door, and the dataplane chooses the backend.
The last layer is CoreDNS, which runs as a Deployment in the kube-system namespace, usually with two replicas, and is exposed by a Service named kube-dns at a fixed ClusterIP, commonly 10.96.0.10. The kubelet writes that address into every pod’s resolver configuration, so every pod in the cluster uses CoreDNS. CoreDNS watches Services and EndpointSlices and answers cluster names from that state, and it forwards everything else, such as example.com, to the upstream resolvers from the node.
Best for: teams that want a mental model of the request path, because most discovery failures can be located by walking these five layers in order.
| Object | DNS record | Resolves to |
|---|---|---|
| Normal Service | my-svc.my-namespace.svc.cluster.local | The ClusterIP |
| Headless Service | my-svc.my-namespace.svc.cluster.local | Every ready pod IP, as several A records |
| StatefulSet pod | pod-0.my-svc.my-namespace.svc.cluster.local | That pod’s IP |
| Named service port | _http._tcp.my-svc.my-namespace.svc.cluster.local | SRV record with the port number |
| ExternalName Service | my-svc.my-namespace.svc.cluster.local | A CNAME pointing outside the cluster |
The table covers the records CoreDNS serves for the common cases. Two details are worth knowing. First, DNS reflects readiness: a pod failing its readiness probe drops out of headless-service DNS answers just as it drops out of EndpointSlices, so a failing pod stops receiving traffic through either path.
Second, regular pods do not get useful DNS names of their own. Only StatefulSet pods, reached through their headless Service, have stable per-pod records, so anything that needs to address individual replicas by name belongs in a StatefulSet. For the broader picture of how these pieces fit into a running application, see our guide to container orchestration.

Headless and ExternalName Services
A headless Service is created by setting clusterIP to None, and it changes what DNS returns. Instead of one A record pointing at the virtual IP, CoreDNS returns one A record per ready pod, so the client sees the pod IPs directly and can choose between them or connect to a specific one. That is how StatefulSets give each replica a stable name such as db-0.db.shop.svc.cluster.local, and it is the right choice when the client needs to know which replica it is talking to, as with a database primary and its replicas.
An ExternalName Service does something different: instead of selecting pods, it returns a CNAME record pointing at a name outside the cluster, such as a managed database hostname. It lets code inside the cluster use a short, stable service name for an external dependency, so the real hostname can change without touching application configuration. Both types are still Services, so they still appear in DNS and in service listings, but neither creates a ClusterIP or an EndpointSlice in the usual sense.
The ndots trap and short names
Short names work because the kubelet writes a search list into each pod’s resolver configuration. For a pod in the shop namespace, the list is shop.svc.cluster.local, svc.cluster.local and cluster.local, so looking up db expands to db.shop.svc.cluster.local, and looking up api.backend expands to api.backend.svc.cluster.local. That is why db works from inside shop and db.shop works from any namespace, and both are the forms you should use in configuration rather than the full name, which hard-codes the cluster domain.
The same configuration has a well-known side effect, controlled by the ndots:5 option. A name with fewer than five dots is tried with every search suffix before it is tried as written, so a lookup of api.stripe.com from inside a pod first tries api.stripe.com.shop.svc.cluster.local, then the other suffixes, and only then the real name.
Every external lookup therefore costs several queries, which sits behind a surprising number of latency incidents, and the fix is usually to write external names with a trailing dot or to use fully qualified names in code that makes many external calls. Our Kubernetes tutorial shows how to inspect a pod’s resolver configuration and test DNS from inside the cluster.
When built-in discovery is not enough
Kubernetes service discovery covers the common case well, but it has limits. It only works inside one cluster, so services in different clusters need multi-cluster networking or a service mesh.
It has no health-aware routing beyond readiness, so it cannot send traffic to the least loaded replica or the nearest one. And it knows nothing about services outside Kubernetes, except through ExternalName services and manual Endpoints.
That is where registries and meshes come in. Consul and Eureka are service registries from outside Kubernetes that applications can query directly, and they suit mixed environments where some services run outside the cluster.
A service mesh such as Istio or Linkerd adds its own discovery and routing on top of Kubernetes, with traffic splitting, retries and observability, at the cost of running a sidecar proxy in every pod. The sensible rule is to use built-in discovery until a concrete requirement forces something more, because each added layer is another system to operate and another place for a failure to hide.
Checklist: diagnosing a service that cannot be reached
- Check the Service has endpoints, because a mismatched selector leaves it with none and DNS still resolves.
- Test DNS from inside a pod first, since a name that fails there is a CoreDNS or configuration problem, not an application one.
- Check the pod’s readiness probe, because a failing pod drops out of EndpointSlices and headless DNS answers.
- Check the port and the named port, since a Service port that does not match the container port silently drops traffic.
- Check NetworkPolicies, which can block traffic between namespaces even when discovery works perfectly.
- Use the short name within a namespace and the namespace-qualified name across namespaces, and avoid hard-coding the full cluster domain.
Frequently asked questions
What is Kubernetes service discovery in simple terms?
Kubernetes service discovery is how applications find each other by name inside a cluster. A Service gives a set of pods a stable name and virtual IP, CoreDNS resolves the name, and the Service dataplane forwards connections to a healthy pod behind it.
What is the difference between a Service and CoreDNS?
CoreDNS handles name resolution: it turns a service name into an address. A Service handles traffic forwarding: its dataplane takes a connection to the virtual IP and delivers it to one healthy backend pod. Both are needed, and a failure in either one looks like the service being unreachable.
What is a headless Service used for?
A headless Service returns pod IPs directly from DNS instead of a virtual IP, which lets clients address individual replicas by name. It is used with StatefulSets, where each pod has a stable identity, and by applications that need to know which replica they are talking to, such as database clusters.
Why does DNS work for a service but the connection still fails?
DNS only proves name resolution works. The connection can still fail because the Service has no endpoints, the port is wrong, the pod is not ready, or a NetworkPolicy blocks the traffic. Check endpoints and readiness next, then the port, then policy.
Do I need a service mesh for service discovery?
No, for most clusters the built-in mechanism is enough. A mesh adds richer routing, retries and observability, but it also adds a sidecar to every pod and a control plane to operate. Adopt one when you have a concrete need it solves, not for discovery alone.






