Day 31/40 — Understanding CoreDNS In Kubernetes
Overview
Video 31 of the Certified Kubernetes Administrator (CKA) 2024 series. A hands-on deep-dive into CoreDNS, the default cluster DNS server that enables service discovery and name resolution inside Kubernetes. This video is the direct application of the external DNS fundamentals covered in Day 30.
Why Cluster DNS Matters
In Kubernetes, Pod IPs are ephemeral. Every restart, reschedule, or scale event gives a Pod a new IP. Services provide stable ClusterIPs, but remembering IPs is impractical. CoreDNS solves this by maintaining an internal DNS namespace so workloads can reach each other by name — for example, database.default.svc.cluster.local — rather than by volatile IP address.
How CoreDNS Works
- A Pod makes a DNS query for a service name (short name or fully qualified domain name).
- The query is forwarded to the cluster DNS Service IP (typically the 10th IP in the Service CIDR, e.g.,
10.96.0.10). - CoreDNS receives the query via its Kubernetes plugin, looks up the Service in the API server, and returns the corresponding ClusterIP.
- For external domains (e.g.,
google.com), CoreDNS forwards the query upstream using theforwardplugin (often to/etc/resolv.confon the node).
CoreDNS Configuration (Corefile)
CoreDNS behavior is driven by the Corefile, stored as a ConfigMap (coredns in the kube-system namespace). A typical Corefile includes:
kubernetesplugin — answers.svc.cluster.localqueries by talking to the API server.forwardplugin — sends unresolved queries to an upstream resolver.cacheplugin — caches responses to reduce API server load.prometheusplugin — exposes metrics on:9153for observability.healthplugin — provides a health endpoint for liveness/readiness probes.
DNS for Kubernetes Service Types
| Service Type | DNS Behavior |
|---|---|
| ClusterIP | my-service.my-namespace.svc.cluster.local resolves to the ClusterIP |
| Headless | Returns A records for each backing Pod IP directly |
| ExternalName | Returns a CNAME record pointing to an external domain |
Cross-Namespace DNS
Services are discoverable across namespaces using the full FQDN:
<service>.<namespace>.svc.cluster.local
Within the same namespace, the short name (my-service) resolves automatically.
Troubleshooting Cluster DNS
| Command | Purpose |
|---|---|
kubectl run -it --rm debug --image=busybox:1.28 --restart=Never -- nslookup kubernetes.default | Test if Pod DNS works |
kubectl logs -n kube-system -l k8s-app=kube-dns | Inspect CoreDNS logs |
kubectl get configmap coredns -n kube-system -o yaml | View and verify the Corefile |
Key Takeaways
- CoreDNS is the default cluster DNS; it runs as a Deployment in
kube-system. - The Corefile defines plugins:
kubernetesfor internal names,forwardfor external names,cachefor performance. - Service DNS names follow the pattern
<service>.<namespace>.svc.cluster.local. - Headless Services return Pod IPs directly; ExternalName Services return a CNAME.
- DNS issues in the CKA exam are often caused by misconfigured Corefile, NetworkPolicy blocking UDP 53, or wrong namespace references.
See Also
Wiki Concepts
- CoreDNS — primary concept page for Kubernetes cluster DNS
- Kubernetes Services — how Services expose workloads and generate DNS entries
- Kubernetes Architecture — where CoreDNS fits in the control plane
- Kubernetes Namespaces — cross-namespace DNS and FQDN patterns
- Kubernetes Network Policies — why egress to CoreDNS must be allowed
- Kubeadm Cluster Setup — CoreDNS stuck in
ContainerCreatingtroubleshooting - Kubernetes ConfigMaps and Secrets — CoreDNS configuration is stored in a ConfigMap
- Kubernetes Health Probes — CoreDNS health plugin
- CKA Certification — exam domain for Services & Networking (~20%)
- DNS Fundamentals — prerequisite external DNS concepts
- DNS Record Types — A, CNAME, and other records mirrored inside the cluster
- DNS Resolution Flow — recursive and iterative resolution principles
Related Sources
- 40 — What Is DNS With @piyushgargdev — prerequisite external DNS fundamentals
- CKA Day 9 — Kubernetes Services Explained — Services that CoreDNS resolves
Creator / Entity
- Tech Tutorials with Piyush — CKA 2024 series creator