logo

Kubernetes - DNS

Last Updated: 2024-01-27

Every Service and Pod defined in the cluster (including the DNS server itself) is assigned a DNS name. You can contact Services with consistent DNS names instead of IP addresses.

Since kubeadm v1.24, the only supported cluster DNS application is CoreDNS. (Support for kube-dns was removed.)

When a pod performs a DNS lookup, the query is first sent to the DNS cache on the node where the pod is running. If the cache does not contain the IP address for the requested hostname, the query is forwarded to the cluster DNS server. This server handles service discovery in Kubernetes.

DNS in Pod: The kubelet running on each Node configures the Pod's /etc/resolv.conf.

If you modify the ConfigMap for kube-dns to include upstreamNameservers, kube-dns forwards all DNS requests except *.cluster.local to those servers.

Kubelet configures Pods' DNS so that running containers can lookup Services by name rather than IP.

What objects get DNS records?

  • Services
  • Pods

Which DNS Plugin to use?

CoreDNS.

kube-dns was a legacy service, now just use coredns; however the service of coredns is still named kube-dns to ensure greater interoperability with workloads that relied on the legacy kube-dns Service name to resolve addresses internal to the cluster."

coredns: watches Endpoints via the discovery.EndpointSlices API.

kube-dns vs coredns: Kube-dns used dnsmasq for caching, which is single threaded C, so it can only use one core per instance. CoreDNS is multi-threaded Go.

Corefile

The Corefile is CoreDNS’s configuration file.

Corefile content can be found in a ConfigMap, normally named coredns or coredns-config in kube-system namespace.