繁体   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?

我有一个部署,其中副本向上和向下扩展,这些都在无头服务下。 我可以查询 ..svc.cluster.local ,它返回所有 pod IP 的列表。

我想知道是否可以查询每个 pod IP 并获取 pod 的主机名? 它适用于同一主机上的 Pod。 但它不能解析来自其他主机的 pod。

我注意到它适用于 StatefulSet。 但它不适用于部署。

这已经在此处针对kube-dns进行了讨论。 已经有更多的讨论也在这里

但是,使用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