How should dynamic Kubernetes/OpenShift DNS resolu

2019-08-26 06:00发布

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条回答
Explosion°爆炸
2楼-- · 2019-08-26 06:14

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.

查看更多
登录 后发表回答