Kubernetes Pod DNS Resolution – How to Resolve Issues

internal-dnskubernetes

Currently able to resolve all services to IP addresses and telnet and ping them. Unable to resolve pods to IP addresses. Though can lookup pod IP addresses with kubectl and telnet and ping them.
How do I need DNS configured to resolve pods in Kubernetes 1.9.6, dns-controller:1.9.1.

Best Answer

@mk_sta 's answer a bit easier to work with you can run this one liner to test your DNS:

kubectl run busybox --image=busybox --rm --attach --command -- sh -c "cat /etc/resolv.conf; nslookup $POD.$NAMESPACE.pod.cluster.local"

Example output:

If you don't see a command prompt, try pressing enter.

Server:         100.64.0.10
Address:        100.64.0.10:53


*** Can't find $POD.$NAMESPACE.pod.cluster.local: No answer

deployment.apps "busybox" deleted

Bonus is that it deletes the deployment/pods after running.


For me the problem was that my pods are in a statefulset and therefore Pod DNS resolution is a bit different. You have to use (for example):

web-{0..N-1}.nginx.default.svc.cluster.local

pod-N.$GOVERNING_STATEFULSET.$NAMESPACE.svc.cluster.local

https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/

That's one thing that can go wrong. You may want to provide more info about your particular case.