CoreDNS
CoreDNS is the default DNS server for Kubernetes clusters. It enables Pods and Services to discover each other by name rather than by volatile IP address.
Why Cluster DNS Matters
In Kubernetes:
- Pod IPs are ephemeral — they change on restart, rescheduling, or scaling.
- Service IPs are stable within the cluster, but remembering them is impractical.
- Applications need to reach other services by a predictable name (e.g.,
database.default.svc.cluster.local).
CoreDNS solves this by maintaining an internal DNS namespace for the cluster.
Relationship to External DNS
This video on external DNS is explicitly framed as a prerequisite for understanding CoreDNS:
“From the next video we’ll be looking into networking stuff related to Kubernetes itself like CoreDNS. I thought it would be a good idea to add a prerequisite because to understand CoreDNS, you need to know how DNS works actually.” — Day 30 CKA Video
The same principles apply:
- A records → map service names to ClusterIPs
- CNAME-like behavior → ExternalName Services proxy to external domains
- Caching → CoreDNS caches responses to reduce API server load
- Hierarchical resolution →
.svc.cluster.localis the cluster domain; queries outside it are forwarded upstream
How CoreDNS Works (High-Level)
- A Pod makes a DNS query for
my-service.default.svc.cluster.local. - The query is sent to the cluster’s DNS Service IP (usually
10.96.0.10or the 10th IP in the Service CIDR). - CoreDNS receives the query.
- CoreDNS checks the Kubernetes plugin — finds the Service’s ClusterIP.
- Returns the IP to the Pod.
For external domains (e.g., google.com), CoreDNS forwards the query to an upstream resolver configured in its Corefile.
CoreDNS Configuration (Corefile)
CoreDNS behavior is defined by the Corefile:
.:53 {
errors
health
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
| Plugin | Purpose |
|---|---|
kubernetes | Answers queries for .svc.cluster.local using the API server |
forward | Sends unresolved queries to upstream DNS (e.g., /etc/resolv.conf) |
cache | Caches responses for 30 seconds |
prometheus | Exposes metrics for monitoring |
DNS in Kubernetes Services
| Service Type | DNS Behavior |
|---|---|
| ClusterIP | my-service.my-namespace.svc.cluster.local → ClusterIP |
| Headless | Returns individual Pod IPs (A records for each endpoint) |
| ExternalName | Returns a CNAME to an external domain |
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 | Check CoreDNS logs |
kubectl get configmap coredns -n kube-system -o yaml | Inspect Corefile |
Related Concepts
- DNS Fundamentals — External DNS basics that underpin CoreDNS
- DNS Record Types — A, CNAME, and other records mirrored inside the cluster
- Kubernetes Services — How Services expose workloads and generate DNS entries
- CKA Certification — Exam context for DNS troubleshooting
Source
- 40 — What Is DNS With @piyushgargdev
- Upcoming CKA videos on CoreDNS (referenced in the series)