簡體   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