Prompt
How do I make services discover each other in Kubernetes?
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
In Kubernetes, the usual way for services to discover each other is through Kubernetes DNS + Services.
The standard pattern
- Create a Service for each set of Pods you want to reach.
- Kubernetes gives that Service a stable DNS name.
- Other Pods can call it by name instead of hardcoding IPs.
Example
If you create a Service named api in the default namespace, other Pods can reach it as:
http://api- or fully qualified:
http://api.default.svc.cluster.local
If it’s in another namespace, use:
http://api.other-namespace.svc.cluster.local
What makes this work
- Service: provides a stable virtual IP and load-balancing to matching Pods.
- CoreDNS: resolves the Service name to the Service IP.
- Labels/selectors: the Service routes traffic to the right Pods.
Typical setup
Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 2
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: my-api:latest
ports:
- containerPort: 8080
Service
apiVersion: v1
kind: Service
metadata:
name: api
spec:
selector:
app: api
ports:
- port: 80
targetPort: 8080
Now other Pods can use:
curl http://api
When to use which Service type
- ClusterIP (default): internal service discovery inside the cluster
- NodePort: expose service on each node
- LoadBalancer: expose externally via cloud load balancer
- Headless Service (
clusterIP: None): direct Pod DNS records, useful for StatefulSets
Headless Service example
Useful when clients need to discover individual Pods rather than a single load-balanced endpoint.
apiVersion: v1
kind: Service
metadata:
name: db
spec:
clusterIP: None
selector:
app: db
ports:
- port: 5432
Then DNS can return Pod IPs directly.
Key things to check if discovery fails
- The Service selector matches Pod labels
- CoreDNS is running
- DNS is enabled in the Pod
- Network policies aren’t blocking traffic
- The app is using the correct Service name/namespace
If you want, I can also show:
- how DNS names are formed in Kubernetes,
- how to do discovery across namespaces,
- or how StatefulSets use headless services.
Brands