Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … nslookup: can't resolve 'my-service' / could not resolve host

Kubernetes DNS not resolving Service names: how to debug

A Pod can't resolve a Service name, so calls fail before any connection.

Kubernetes

What it means

Pods resolve names through CoreDNS at the address in their /etc/resolv.conf. Short names only work inside the same namespace; other namespaces need name.namespace.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. Wrong name or namespace (my-svc from another namespace)

Check:

kubectl exec <pod> -- nslookup my-svc.<ns>.svc.cluster.local

Fix: Use name.namespace or the full name.

2. The Pod's dnsPolicy or dnsConfig overrides cluster DNS

Check:

kubectl exec <pod> -- cat /etc/resolv.conf

Fix: Use dnsPolicy ClusterFirst unless there's a reason not to.

3. A NetworkPolicy blocks egress to CoreDNS on port 53

Check:

kubectl get networkpolicy -n <ns>

Fix: Allow egress to kube-dns (UDP and TCP 53).

4. CoreDNS itself is down or misconfigured

Check:

kubectl -n kube-system get pods -l k8s-app=kube-dns; kubectl -n kube-system logs -l k8s-app=kube-dns

Fix: Fix the Corefile or the CoreDNS Deployment.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors