如何将 Kubernetes DNS 用于 Pod? [英] how to use Kubernetes DNS for pods?

查看:32
本文介绍了如何将 Kubernetes DNS 用于 Pod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 GKE 上,kube-dns 在我的节点上运行,我可以看到 docker 容器.

On GKE, kube-dns is running on my nodes, I can see the docker containers.

我确实可以按名称访问服务,这对于负载平衡是非常合适的解决方案的所有这些应用程序都非常有用,但是我将如何使用 DNS 访问单个 Pod?

I do have access to Services by name, which is great for all these applications where load balancing is a perfectly suitable solution, but how would I use the DNS to access individual pods?

我知道我可以在 API 中查找特定的 pod,但我需要自己更新 hosts 文件,并继续观察 pod 列表.DNS 应该为我做到这一点,那么在 pod 中使用它意味着什么?

I know I can look up specific pods in the API, but I need to update the hosts file myself, and keep watching the pod list. DNS is supposed to do that for me so how is it meant to be used within a pod?

Kubernetes 文档说需要将 DNS 信息传递给 kubelet,但我无法在我知道的 GKE 上访问该信息,所以它是不是在 GKE 上没有这样设置,或者有什么办法可以激活它?

The Kubernetes doc says the DNS info needs to be passed to the kubelet but I have no access to that on GKE that I know of, so is it just not setup that way on GKE or is there something to do to activate it?

我的一些服务(特别是 Zookeeper)自己知道其他节点,并尝试通过主机名(即 pod 名称)连接到它们,除非我更新 hosts 自己归档.我想为此使用集成的 DNS 服务.

Some of my services (zookeeper in particular) is aware of other nodes on its own, and tries to connect to them by host name (that is pod name) and that fails unless I update the hosts file myself. I would like to use the integrated DNS service for that.

任何有关如何执行此操作的指导将不胜感激.

Any guidance on how to do this would be appreciated.

谢谢

推荐答案

UPDATE

根据文档,现在的格式是:

According to the docs, the format is now:

_my-port-name._my-port-protocol.my-svc.my-namespace.svc.cluster.local

在此处查看相关文档:https://kubernetes.io/docs/concepts/services-网络/dns-pod-service/#pods

原始答案:

截至目前,这实际上是不可能的……但 Kubernetes 团队正在研究它.

as of this date, this is actually not possible... but it is being looked at by the Kubernetes team.

看到这个问题:https://github.com/kubernetes/kubernetes/issues/13552

更新:

DNS 自 09/2015 起可用于 Pod参见 PR:https://github.com/kubernetes/kubernetes/pull/13759

DNS is available for Pods since 09/2015 See PR:https://github.com/kubernetes/kubernetes/pull/13759

简而言之:

这将以 pods 的形式提供 dns..pod. 目前可以禁用,但是为所有 Pod 开启或关闭.

This will give pods dns in the form of <podIP>.<namespace>.pod.<clusterSuffix> Currently can be disabled, but is either on for all pods or off.

这篇关于如何将 Kubernetes DNS 用于 Pod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆