CoreDNS in the Cluster
CoreDNS in the Cluster
Every cluster runs a DNS service — CoreDNS by default — as a Deployment with a ClusterIP, typically 10.96.0.10 under kubeadm. Pods receive resolver configuration through dnsPolicy:
- ClusterFirst (default) — cluster names resolve via CoreDNS; unknown names fall back to the host's upstream resolvers via the
forwardplugin. - ClusterFirst with hostNetwork — requires explicit handling since the pod shares the node's network.
- None — ignore cluster DNS entirely and use
dnsConfignameservers you supply.
The magic is search domains: a pod gets ns.svc.cluster.local svc.cluster.local cluster.local appended, so mysql inside namespace shop resolves to mysql.shop.svc.cluster.local automatically.
Records and Configuration
Records and Configuration
Two record shapes matter:
<service>.<ns>.svc.cluster.local→ ClusterIP of a normal Service.<pod-ip-dashed>.<service>.<ns>.svc.cluster.local→ individual pods of a headless Service (10-244-1-7.my-hl.ns.svc.cluster.local).
CoreDNS reads a ConfigMap, kube-system/coredns, reloaded automatically when it changes:
plugins:
- name: forward
arguments: . 1.1.1.1
- name: cache
parameters: 30
Each ready pod of a Service is registered; SRV records (_http._tcp.my-svc) expose ports for clients that need them.
Pitfalls and Interview Angles
Pitfalls and Interview Angles
Pitfall 1 — debugging app errors as DNS errors. Prove resolution first: kubectl run dnsutils --image=busybox:1.36 --rm -it -- nslookup mysql.shop. If that works, the failure is connectivity or credentials, not DNS.
Pitfall 2 — ndots and slow lookups. With ndots:5, a name like api.example.com triggers up to five search-domain probes before the real query, adding latency. Add a trailing dot (FQDN) or raise dnsConfig.options ndots for chatty clients.
Interview-ready: name CoreDNS and its ConfigMap, explain ClusterFirst search domains, and answer "pods cannot resolve services" with the check order: CoreDNS pods healthy → cluster domain matches → headless versus regular record shape → upstream forward for external names.
Quiz
1. What does dnsPolicy: ClusterFirst do for unknown names?
2. Which DNS record points at an individual pod of a headless Service?
3. Where is CoreDNS configuration stored?
Flashcards
Question
Default cluster DNS
Click to reveal answer
Answer
CoreDNS as a Deployment, typically ClusterIP 10.96.0.10 under kubeadm defaults.
Question
Search domains effect
Click to reveal answer
Answer
ns.svc.cluster.local, svc.cluster.local, cluster.local get appended, so short names resolve.
Question
ndots pitfall
Click to reveal answer
Answer
ndots:5 makes dotted external names try search paths first — use a trailing dot for FQDNs.
Question
CoreDNS config home
Click to reveal answer
Answer
kube-system/coredns ConfigMap (Corefile), reloaded on change.
Revision Notes
Key Takeaways
- 1. ClusterFirst plus search domains explain short-name resolution
- 2. Headless Services change the record shape to per-pod names
- 3. Prove DNS with nslookup before blaming it
Interview Tips
- • Walk the resolution path: resolv.conf → search domains → CoreDNS → forward
- • For "cannot resolve svc" give a three-command debug sequence
Cheat Sheet
CoreDNS + ClusterFirst search domains (ns.svc..., svc..., cluster.local). Headless = per-pod A records. Config: coredns ConfigMap. Debug: nslookup from a test pod.