Cluster DNS and search domains
Start with a name, not a Pod IP
A shop frontend in namespace shop needs an inventory Service in namespace books. Kubernetes cluster DNS gives the Service a name that stays useful when backend Pods are replaced. The Service is named inventory; the fictional cluster domain is cluster.test. From the frontend, use inventory.books or the explicit DNS name inventory.books.svc.cluster.test.. The final dot marks an absolute DNS name. A short name alone normally searches the caller’s namespace first. This lesson builds on Service discovery and the Pod network. All addresses and responses are synthetic.
Read the resolver configuration
On a Linux Pod, /etc/resolv.conf commonly describes the DNS server, search suffixes and resolver options. Here the nameserver is the cluster DNS Service IP. The search list starts with the client namespace, then the service and cluster suffixes. The actual domain and nameserver depend on cluster configuration. A Pod using a different DNS policy may see different values. Inspect the affected Pod rather than assuming this file matches the host.
nameserver 10.96.0.10search shop.svc.cluster.test svc.cluster.test cluster.testoptions ndots:5Understand search suffixes and ndots
With a typical glibc-style resolver and ndots:5, a name with fewer than five dots is generally tried with search suffixes before an absolute attempt. For inventory.books, the first candidate in this fixture is inventory.books.shop.svc.cluster.test.; the next is inventory.books.svc.cluster.test.. A successful response may stop further searching. A name with at least five dots is normally tried as absolute first. An ending dot avoids suffix expansion regardless of ndots. The following is a candidate-order illustration, not a guarantee of packets sent by every language runtime or DNS client. Even a name that looks fully qualified without the trailing dot can generate extra searches.
inventory.books.shop.svc.cluster.test. -> NXDOMAIN (fixture)inventory.books.svc.cluster.test. -> 10.96.0.40 (fixture)Read Service and Pod record types
A normal IPv4 ClusterIP Service generally has an A record for its virtual IP; IPv6 Services use AAAA records as applicable. A headless Service uses backend addresses instead, subject to readiness and publication settings. Named Service ports can produce SRV records that include port and target information. An eligible Pod with hostname and subdomain matching a headless Service can receive a Pod-specific name. Do not rely on arbitrary Pod-IP-derived names across DNS implementations. A records carry addresses, not HTTP ports, TLS settings or proof of application health.
Choose the DNS policy deliberately
ClusterFirst is the normal default for ordinary Pods and delegates names outside the cluster domain to configured upstream resolution. Default inherits node resolver configuration. For host-networked Pods that need cluster DNS, ClusterFirstWithHostNet is the relevant policy on supported platforms. None requires explicit dnsConfig; it is not a switch that automatically supplies cluster DNS. Additional search suffixes, nameservers and options can be specified in dnsConfig subject to platform limits. Do not replace cluster DNS with a public resolver as a generic fix: it may not know internal names.
apiVersion: v1kind: Podmetadata: name: dns-study namespace: shopspec: dnsPolicy: ClusterFirst containers: - name: client image: registry.invalid/study/client:offlinePractice with an absolute name
Open lab-fixtures/coredns/resolv.conf.txt and search-cases.json. Predict the first two candidates for inventory.books and the only candidate for inventory.books.svc.cluster.test.. Explain why the short name inventory is a different query from a Pod in shop and from a Pod in books. In an approved lab with an existing DNS-capable client, compare an absolute lookup with a relative lookup. The manifest above uses a deliberately non-deployable image. The fixture does not run DNS or pull images.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Cluster DNS and search domains — knowledge check
Interpret synthetic DNS and Service evidence.
A Pod in shop needs inventory in books. Which name explicitly identifies the Service without search expansion?
With the shown search list and ndots:5, which candidate is normally tried first for inventory.books?
What does a normal IPv4 ClusterIP Service A record identify?
What distinguishes a headless Service DNS answer?
Which policy is normally used for an ordinary Pod that needs cluster DNS?