Pass IP of kube-dns as env to container

3/23/2017

Is there a way to pass the kube-dns server IP to the container so that services inside the container can resolve the names properly?

I am trying to run nginx and it needs a resolver directive to be specified to resolve names against a DNS server.

I do not want to use public DNS servers; only the one provided by kube-dns.

Also, I need a dynamic way to pass the IP as the DNS server IP can change across various cloud platforms or bare-metal configurations. So, I cannot use a hardcoded 10.0.0.10 IP.

-- krish7919
kube-dns
kubernetes

1 Answer

3/23/2017

Alright, it seems quite simple. A few points I had missed.

  1. kube-dns runs as a Kubernetes Service in the kube-system namespace.
  2. The DNS name for the service is kube-dns.kube-system.svc.cluster.local
  3. We can pass this to the container using env.

EDIT:

It seems I was looking at the wrong place. It indeed uses the local resolver resolve. The problem is I hit a 'feature' in NGINX which caches the lookups for 300 secs and causes name resolution failure, and I was investigating k8s.

-- krish7919
Source: StackOverflow