Every Kubernetes cluster has CoreDNS running as the in-cluster resolver, and most operators never touch it — until they need to. This article walks the default Corefile the cluster ships with, explains what each plugin does and in what order, and shows the customizations we make most often: stub-domain forwarding to on-prem DNS, cache tuning, and emergency overrides. The deliverable is the mental model to read and safely edit the coredns ConfigMap.
How to verify
Before editing, dump the current Corefile and confirm the pods are healthy. The ConfigMap is coredns in the kube-system namespace:
kubectl -n kube-system get configmap coredns -o yaml
kubectl -n kube-system get pods -l k8s-app=kube-dns -o wide
kubectl -n kube-system logs -l k8s-app=kube-dns --tail=50
kubectl run -i --rm busy --image=busybox:1.36 --restart=Never -- nslookup kubernetes.default
The last command runs a one-shot pod that resolves kubernetes.default — the canonical “is cluster DNS working” check.
What’s happening
CoreDNS is a plugin-driven DNS server. Unlike BIND or PowerDNS, it has no built-in opinion about what a DNS server does — every behaviour (zone files, caching, Kubernetes service resolution, forwarding) is a plugin compiled into the binary. The Corefile is a tiny DSL that wires plugins together per “server block,” where each block listens on a port/scheme and handles a set of zones.
A default Kubernetes Corefile looks like this:
.:53 {
errors
health {
lameduck 5s
}
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . /etc/resolv.conf {
max_concurrent 1000
}
cache 30
loop
reload
loadbalance
}
Each line is a plugin. They execute in the order they appear for write-path plugins (errors, cache), and in the order they appear in the dispatch chain for query-path plugins. The most important ones:
kubernetes— resolves*.cluster.localand reverse zones from the API server. The cluster’s service-discovery machinery.forward . /etc/resolv.conf— for any name not matched above, ask the upstream resolver listed in the pod’s resolv.conf (which is the node’s resolv.conf).cache 30— cache positive responses for up to 30 seconds, negative for the SOA minimum.loop— detects when CoreDNS would forward to itself (e.g.127.0.0.53upstream loop) and panics rather than livelock.reload— watches the ConfigMap and reloads automatically on change. No pod restart needed.
The cluster.local zone is convention; you can rename it at cluster install time but most clusters keep it.
The procedure
-
Stub-domain forwarding to on-prem DNS. Most common customization. A cluster needs to resolve
*.corp.example.comagainst an internal DNS that holds those zones:.:53 { errors health { lameduck 5s } ready kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure fallthrough in-addr.arpa ip6.arpa ttl 30 } prometheus :9153 corp.example.com:53 { forward . 10.50.0.10 10.50.0.11 cache 60 } forward . /etc/resolv.conf cache 30 loop reload loadbalance }The new server block
corp.example.com:53handles only that zone. Order matters because of the way CoreDNS dispatches — the most specific block wins. -
Apply the ConfigMap change. Edit and apply:
kubectl -n kube-system edit configmap coredns kubectl -n kube-system logs -l k8s-app=kube-dns --tail=30 # the reload plugin picks up changes within ~30 secondsIf you mistyped the Corefile, the
reloadplugin refuses to apply it and logs the error. The running pods keep serving the old config. Always tail the logs after an edit. -
Increase cache for high-QPS workloads. Default
cache 30is conservative. For workloads that resolve the same name millions of times per minute (microservices calling each other by service name), bump it:cache { success 2048 60 denial 1024 5 }success 2048 60means up to 2048 cached positive responses with TTL 60. The cache plugin is per-pod, so total cluster memory scales with replica count. -
Add a hosts plugin override (emergency). Sometimes you need to force a name to resolve to a specific IP cluster-wide. The
hostsplugin reads inline records:.:53 { errors health { lameduck 5s } hosts { 203.0.113.50 api.partner.example.com fallthrough } kubernetes cluster.local in-addr.arpa ip6.arpa { ... } ... }fallthroughis non-negotiable — without it, names not in the hosts list return NXDOMAIN instead of falling through to the next plugin. -
Verify after every change. Run the canonical lookups and a stub-domain lookup:
kubectl run -i --rm busy --image=busybox:1.36 --restart=Never -- sh -c ' nslookup kubernetes.default nslookup nginx.default.svc.cluster.local nslookup intranet.corp.example.com nslookup google.com'All four should resolve. If any fails, roll back the ConfigMap and re-check.
Common pitfalls
- Editing the Deployment image instead of the ConfigMap. New operators sometimes “fix DNS” by restarting the CoreDNS pods. The Corefile lives in a ConfigMap; pod restart loads the old (or new) version of the same ConfigMap. Edit the ConfigMap, not the pods.
- Forgetting
fallthroughon the hosts plugin. Returns NXDOMAIN for everything not in the hosts list — cluster DNS appears broken even though the pod is healthy. - Stub-domain block ordering. A
.example.com:53block beforekuberneteswill swallowkubernetes.default.svc.cluster.localif the zone overlaps. Put the broadest zones last. loopplugin tripping. If a pod’s resolv.conf points at CoreDNS’s own ClusterIP and the upstream forward is back to the host’s resolv.conf which also points to CoreDNS, you get a loop. Theloopplugin detects this and crashes the pod — a feature, not a bug. Fix the node’s/etc/resolv.conf.- NodeLocal DNSCache and the same Corefile. Some clusters run a per-node DNS cache (
node-local-dns) in front of CoreDNS. Its Corefile is a separate ConfigMap (node-local-dns) with its own forward target. Editing the wrong one is a common confusion.
In the engagements we run, the CoreDNS ConfigMap is one of the most-impactful files in the cluster — a misedit takes down service discovery for the whole platform. We treat the Corefile like production code: review the diff, apply in a non-prod cluster first, watch the logs of every CoreDNS pod after the change, and roll back fast if anything goes weird. See our managed operations service for the broader operating model.