K8s sets up a built-in DNS server on the cluster to resolve pod and service names to their IPs. Prior to K8s v1.12, it was kube-dns. From v1.12 onwards, CoreDNS is the recommended DNS solution. When setting up the cluster using KubeAdmin, CoreDNS is deployed as a deployment of 2 replicas for high availability in the kube-system namespace.

Untitled

Untitled

Each CoreDNS pod runs the Coredns executable which uses the config /etc/coredns/Corefile. The Corefile is passed to the deployment as a ConfigMap named coredns so that it can be easily edited.

To allow other pods to reach the CoreDNS pods, a service named kube-dns is created in the kube-system namespace. The IP address of this service is configured as the nameserver in all the pods’ /etc/resolv.conf by the Kubelet.

DNS for Services

Whenever a service is created, an entry is added to the DNS server to map the service name to its IP. Now, any pod within the same namespace can reach the service by its name. Pods in some other namespace can reach the service at <service-name>.<namespace> where namespace is the namespace in which the service is present.

Untitled

DNS for Pods

DNS records are not created for pods by default. But we can enable it. In this case, the pod name is generated by replacing . with - in the IP address of the pod.

Untitled