简体   繁体   English

是否可以通过反向 dns 查询 POD IP 地址来获取其用于 Kubernetes 部署的主机名?

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

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.我可以查询 ..svc.cluster.local ,它返回所有 pod IP 的列表。

I wanted to know if its possible to query for each pod IP and get the hostname of the pod?我想知道是否可以查询每个 pod IP 并获取 pod 的主机名? It works for Pods on the same host machine.它适用于同一主机上的 Pod。 But its not resolving the pods from other hosts.但它不能解析来自其他主机的 pod。

I noticed that it works for a StatefulSet.我注意到它适用于 StatefulSet。 But its not working for Deployment.但它不适用于部署。

This has already been discussed here for kube-dns .这已经在此处针对kube-dns进行了讨论。 There has been more discussion here too .已经有更多的讨论也在这里

However, PTR records work fine for me with coredns and K8s 1.12:但是,使用coredns和 K8s 1.12,PTR 记录对我来说很好用:

$ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM