Kubernetes Internal DNS (Search Base)
Luke Hebert
- 2 minutes read - 328 wordsKubernetes provides a built-in DNS service that assigns predictable names to Services and Pods within a cluster. By default, pods use cluster.local as their search base for internal DNS resolution, enabling communication through human-readable names rather than ephemeral IP addresses. The system supports both fully qualified domain names and simplified names via automatic search domain appending, and the cluster domain can be customized at setup time if needed.
By default, Kubernetes pods use cluster.local as their default search base for internal DNS resolution.
The configuration of CoreDNS is passed into CoreDNS as a config map when a cluster is deployed using kubeadm; otherwise, it is likely to be located in /etc/coredns/Corefile.
Individual pods use the service kube-dns. Pods point at the address for this service. The kubelet will automatically configure this for deployed pods.
Breakdown
- DNS Resolution: Kubernetes provides a built-in DNS service (like CoreDNS) that assigns DNS names to Services and Pods within the cluster.
- Service DNS Name: A service’s DNS name follows the format
<service-name>.<namespace-name>.svc.cluster.local, for example,my-service.default.svc.cluster.local. - Pod DNS Name (StatefulSets): Pods within StatefulSets or with a defined hostname/subdomain get DNS names like
<pod-name>.<headless-service-name>.<namespace>.svc.cluster.local. - Simplified Communication: This system allows pods to communicate with each other using these predictable DNS names instead of ephemeral IP addresses.
- Search Domains: When a pod attempts to resolve an unqualified hostname (e.g., just
my-service), Kubernetes automatically appends the configured search domains, including<requester_namespace>.svc.cluster.local,svc.cluster.local, andcluster.local. This allows pods within the same namespace to use simpler names for services in that namespace. - cluster.local as the Default:
cluster.localis the standard and commonly used cluster domain suffix. - Customization: While
cluster.localis the default, you can customize the cluster domain name when setting up your Kubernetes cluster if needed.
In essence, when a pod makes a DNS query for a name that does not include a fully qualified domain name, Kubernetes’s DNS system appends the relevant search suffixes, including cluster.local, to try and resolve the name within the cluster’s internal DNS hierarchy.