Kubernetes and container name resolution

3/25/2017

I am trying to set up MongoDB and MongoDB monitoring agent on a kubernetes cluster.

The monitoring agent first queries the service endpoint for the mongodb instance, and receives the hostname as a response. It then stops using the service endpoint, and starts to use the hostname to connect to the instance which fails as there is no resolution to get the container name resolved.

I think I can use a headless service to achieve this, although using headless service is not an option.

Is there any way to enable hostname resolution for containers/pods in Kubernetes or inject custom DNS records in kube-dns?

-- krish7919
dns
kube-dns
kubernetes
mongodb

1 Answer

4/5/2017

You should create a StatefulSet for your use case. Because you need your pod to have a unique identifier. To quote the docs, StatefulSets have:

StatefulSet Pods have a unique identity that is comprised of an ordinal, a stable network identity, and stable storage. The identity sticks to the Pod, regardless of which node it’s (re)scheduled on.

So if you are using Deployment object for MongoDB modify it to StatefulSet object type.

Your pods will be name resolved as well.

Docs:

-- surajd
Source: StackOverflow