Kubernetes - how to check current domain set by --cluster-domain from pod?

Andy Luo picture Andy Luo · Oct 23, 2018 · Viewed 16.5k times · Source

Kubernetes admin can use --cluster-domain to customize cluster domain instead of using default one: cluster.local Kubelet Configs.

So the question is, how does an application pod check this domain in runtime?

Answer

Rico picture Rico · Oct 23, 2018

It needs to be configured on the DNS server.

Either kube-dns or coredns (Favored on newer K8s versions)

kube-dns: it's a cli option --domain

core-dns: you can configure the K8s ConfigMap

And you see here:

The kubelet passes DNS to each container with the --cluster-dns= flag.

If you'd like to know how a pod resolves cluster.local it does it through the /etc/resolv.conf that the kubelet mounts on every pod. The content is something like this:

$ cat /etc/resolv.conf
nameserver 10.96.0.10
search <namespace>.svc.cluster.local svc.cluster.local cluster.local <nod-domain>
options ndots:5

10.96.0.10 is your coredns or kube-dns cluster IP address.