kubernetes - k8s 中不同命名空间的服务的 DNS 名称是什么?

标签 kubernetes dns fqdn

在命名空间 A 中,我有一个服务 nginx 正在运行。在命名空间 B 中,我可以使用 nginx.Anginx.A.svc.cluster.local 来访问命名空间 A 中的 nginx .

那么这两者有什么区别呢?更推荐哪一款?为什么?

最佳答案

两种形式都被认为是正确的(与 this 文章比较)并且在大多数情况下工作正常但是我可以在 github 上发现一些问题当人们遇到一些仅与短名称解析相关的问题,例如:

https://github.com/kubernetes/dns/issues/109

https://github.com/kubernetes/kubernetes/issues/10014

正如您在官方 Kubernetes 文档(ref1ref2)中所读到的,它建议在跨命名空间访问服务时使用长格式:

When you create a Service, it creates a corresponding DNS entry. This entry is of the form <service-name>.<namespace-name>.svc.cluster.local, which means that if a container just uses <service-name>, it will resolve to the service which is local to a namespace. This is useful for using the same configuration across multiple namespaces such as Development, Staging and Production. If you want to reach across namespaces, you need to use the fully qualified domain name (FQDN).

在我看来,坚持FQDN (fully qualified domain name)要好得多标准且通常是明确的被认为是比隐含更好的做法。

关于kubernetes - k8s 中不同命名空间的服务的 DNS 名称是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58372362/

相关文章:

kubernetes - 用于自定义或运算符的kubectl vs json API

kubernetes - PVC 处于待定状态

dns - AWS 负载均衡器需要 @ cname 记录,但这会覆盖我的 @ MX 记录

azure - 向 Google Play 证明 Azure 网站所有权

windows - 命令提示符 DNS 查找

c++ - 如何获取引用 FQDN 的 IP 列表

java - 如何使用intellij正确远程调试pod?

python - socket.getfqdn() 不返回域,但 socket.gethostname() 返回域吗?

networking - 如何将Docker容器隐藏在单个主机名后面

docker - 无法从 Postman 的 k8s-Skaffold 中的 Express API 获得响应