How should dynamic Kubernetes/OpenShift DNS resolution be configured?

蓝咒 提交于 2019-12-25 01:49:39

问题


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

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?

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.


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/47820390/how-should-dynamic-kubernetes-openshift-dns-resolution-be-configured

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!