Prompt
Kubernetes service discovery not working between pods
Latest observation
If Kubernetes service discovery is failing between pods, it’s usually one of a few common issues: the Service doesn’t have endpoints, DNS isn’t resolving, network policies are blocking traffic, or the app is using the wrong hostname/port.
Here’s a quick troubleshooting checklist:
1) Verify the Service exists
kubectl get svc
kubectl describe svc <service-name>
Check:
- Correct name
- Correct namespace
- Correct selector labels
- Correct targetPort/port
2) Check the Service has endpoints
kubectl get endpoints <service-name>
If this is empty, the Service isn’t selecting any pods. Common causes:
- Pod labels don’t match the Service selector
- Pods aren’t ready
- Wrong namespace
Also check:
kubectl get pods --show-labels
3) Confirm DNS resolution from inside a pod
Run a debug pod:
kubectl run -it --rm debug --image=busybox:1.36 --restart=Never -- sh
Inside it:
nslookup <service-name>
nslookup <service-name>.<namespace>.svc.cluster.local
If DNS fails:
- Check CoreDNS:
kubectl get pods -n kube-system | grep coredns
kubectl logs -n kube-system deploy/coredns
4) Test connectivity to the Service
From the debug pod:
wget -qO- http://<service-name>:<port>
# or
nc -vz <service-name> <port>
If DNS works but connection fails:
- The app may not be listening on the expected port
- Service targetPort may be wrong
- NetworkPolicy may be blocking traffic
5) Check NetworkPolicies
kubectl get networkpolicy -A
If policies exist, they may be denying pod-to-pod traffic unless explicitly allowed.
6) Ensure you’re using the right namespace
If the service is in another namespace, use:
<service-name>.<namespace>.svc.cluster.local
Or create/use a service in the same namespace.
7) Check the pod is actually serving traffic
Inside the target pod:
kubectl exec -it <pod-name> -- sh
netstat -tlnp
# or
ss -tlnp
Make sure the app binds to 0.0.0.0, not just 127.0.0.1.
8) Confirm readiness probes aren’t preventing endpoints
If pods are not Ready, they won’t be added to endpoints.
kubectl describe pod <pod-name>
Common mistakes
- Service selector labels don’t match pod labels
- Using pod IP instead of Service DNS name
- Wrong namespace
- Wrong port / targetPort
- App listening on localhost only
- NetworkPolicy blocking traffic
- CoreDNS issues
If you want, I can help you debug it step-by-step
Paste the output of these commands:
kubectl get svc
kubectl get pods -o wide --show-labels
kubectl get endpoints
kubectl describe svc <service-name>
kubectl describe pod <one-pod-name>
And I can help pinpoint the issue.
Brands