Is it possible to Reverse-dns query for a POD IP address to get its hostname for a Kubernetes Deployment?

11/2/2018

I have a deployment where the replicas scale up and down which are all under a headless service. I am able to query ..svc.cluster.local which returns list of all pod IPs.

I wanted to know if its possible to query for each pod IP and get the hostname of the pod? It works for Pods on the same host machine. But its not resolving the pods from other hosts.

I noticed that it works for a StatefulSet. But its not working for Deployment.

-- sai guru datt manchikanti
kube-dns
kube-proxy
kubernetes

1 Answer

11/2/2018

This has already been discussed here for kube-dns. There has been more discussion here too.

However, PTR records work fine for me with coredns and K8s 1.12:

$ kubectl get pod helloworld-xxxxxxxxxx-xxxxx -o=jsonpath="{.metadata.annotations['cni\.projectcalico\.org/podIP']}" | cut -d "/" -f 1
192.168.11.28
# Connect to another pod   
$ kubectl exec -it anotherpod-svc-xxxxxxxxxx-xxxxx bash
root@anotherpod-xxxxxxxxxx-xxxxx:/# dig +short -x 192.168.11.28
192-168-11-28.helloworld.default.svc.cluster.local.
root@anotherpod-xxxxxxxxxx-xxxxx:/# dig +short 192-168-11-28.helloworld.default.svc.cluster.local
192.168.11.28

# Another helloworld pod on a different physical machine
$ kubectl get pod helloworld-xxxxxxxxxx-xxxxx -o=jsonpath="{.metadata.annotations['cni\.projectcalico\.org/podIP']}" | cut -d "/" -f 1
192.168.4.6
# Connect to another pod   
$ kubectl exec -it anotherpod-svc-xxxxxxxxxx-xxxxx bash
root@anotherpod-svc-xxxxxxxxxx-xxxxx:/# dig +short -x 192.168.4.6
192-168-4-6.helloworld.default.svc.cluster.local.
root@anotherpod-xxxxxxxxxx-xxxxx:/# dig +short 192-168-4-6.helloworld.default.svc.cluster.local
192.168.4.6
-- Rico
Source: StackOverflow