如何配置动态Kubernetes/OpenShift DNS解析? [英] How should dynamic Kubernetes/OpenShift DNS resolution be configured?

查看:174
本文介绍了如何配置动态Kubernetes/OpenShift DNS解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到与此相关的信息,这就是为什么我在这里问这个问题.

I'm unable to find relevant information on this, which is why I'm asking the question here.

与其使用/etc/hosts这不是一种将Kubernetes容器名称解析为其服务IP地址的骇人解决方案,最好的方法是自动或动态地将新的Kubernetes容器映射到其服务IP?

Instead of using /etc/hosts which is a hacky solution for resolving Kubernetes container names to their service IP addresses, what would the best method be to automatically or dynamically map new Kubernetes pods to their service IPs?

我听说使用/etc/resolv.conf是这样的一种方法,但是无法确切找到在这种情况下该文件的配置方式.

I've heard using /etc/resolv.conf is one such method, but was unable to find exactly how that file should be configured for this scenario.

推荐答案

如果您使用的是OpenShift,它将使用内部DNS进行部署.创建 Service 对象时,它将自动具有其服务名称,并在内部DNS中设置为主机名,并映射到该服务的IP地址.

If you are using OpenShift it deploys with an internal DNS. When you create a Service object it will automatically have its service name, setup as a hostname in the internal DNS, with it mapping to the IP address of the service.

该服务上的标签选择器还与 Pods 上的标签匹配,该Pod的IP地址将作为该服务和内部网络设置的端点关联,以便与该服务IP的连接直接或在通过主机名(服务名)进行DNS查找之后,会将连接路由到其中一个容器.

Further the label selectors on the service are matched against labels on Pods, the IP addresses of the pods will be associated as an endpoint for that service and internal network setup so that connection to the service IP directly, or after DNS lookup by hostname (service name), will route connection through to one of the pods.

因此,所有这些都自动为您完成,您无需执行任何操作.如果您正在使用oc new-app在OpenShift中部署应用程序,甚至会自动为您创建服务对象.

So all of this is done for you automatically and you don't need to do anything. The service object is even created for you automatically if you are using oc new-app to deploy applications in OpenShift.

这篇关于如何配置动态Kubernetes/OpenShift DNS解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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