Sub topic 11
Checking CoreDNS: Pods, logs, and the Corefile
This chapter assumes you can run kubectl get, describe, logs, and exec. It also assumes you know that Pods resolve Service names through the cluster DNS server. Here you will check the server itself when name resolution fails.
When to suspect CoreDNS
Suspect CoreDNS when every name fails to resolve from every Pod, or when lookups time out instead of returning NXDOMAIN. If only one name fails, the cause is usually a wrong name, a wrong namespace, or a missing Service. Check those first.
CoreDNS runs as a Deployment in the kube-system namespace. Its Pods carry the label k8s-app=kube-dns, and a Service named kube-dns fronts them. The Pod's resolv.conf points at that Service's ClusterIP. The Service keeps the old name even though the software is CoreDNS.
Step 1: Pod status
kubectl -n kube-system get pods -l k8s-app=kube-dns
kubectl -n kube-system get service kube-dnsLook for these conditions:
- The Pods should be
RunningandREADY 1/1. ACrashLoopBackOffstatus points to a bad configuration or a loop, so read the logs next. - A
PendingPod points to scheduling or CNI problems. Runkubectl describeon the Pod. - The
kube-dnsService must exist and have endpoints. Check withkubectl -n kube-system get endpointslices -l kubernetes.io/service-name=kube-dns. No endpoints means no ready CoreDNS Pod, so every lookup times out.
Step 2: Logs
kubectl -n kube-system logs -l k8s-app=kube-dnsCommon messages and what they mean:
| Log message | Likely cause |
|---|---|
| `Loop ... detected` | The upstream resolver forwards back to CoreDNS. CoreDNS stops on purpose. |
| `i/o timeout` to an upstream IP | The node cannot reach its upstream resolver. External names fail while cluster names work. |
| `Failed to list *v1.Service` or `connection refused` to the API server | CoreDNS cannot reach the API server, so it cannot learn about Services. |
| `plugin/errors: ... SERVFAIL` | An upstream or plugin failed for that query. |
Logs only show query lines if the log plugin is enabled. The default configuration usually enables only errors, so a quiet log does not prove that queries are arriving.
Step 3: The Corefile
CoreDNS reads its configuration, called the Corefile, from a ConfigMap.
kubectl -n kube-system get configmap coredns -o yamlA typical Corefile looks like this:
.:53 {
errors
health
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
forward . /etc/resolv.conf
cache 30
loop
reload
}Check these lines:
kubernetes cluster.localmakes CoreDNS answer Service and Pod names. If the domain differs from thesearchdomains in a Pod'sresolv.conf, short names will not resolve.forward . /etc/resolv.confsends everything else to the node's resolvers. If those resolvers are wrong, external lookups fail.loopdetects forwarding loops and stops CoreDNS when it finds one.reloadpicks up ConfigMap changes automatically, after a short delay.
Corefile contents vary by distribution and by managed service, so compare against your cluster's own defaults.
Confirming from a Pod
After a fix, test from inside the cluster. Run nslookup web.default.svc.cluster.local in a temporary Pod. Then run nslookup example.com to test the upstream path. Comparing the two results tells you which half of the configuration is at fault.
Exercise
Every Pod in the cluster times out on all DNS lookups, including kubernetes.default. The CoreDNS Pods show Running. Which check do you run next, and what result would explain the failure?
Show answer
Check that the kube-dns Service has endpoints, for example with kubectl -n kube-system get endpointslices -l kubernetes.io/service-name=kube-dns. If the list is empty, the Pods are not ready, or their labels do not match the Service selector, so queries reach no backend. Reading the CoreDNS logs and the ready status of each Pod is the follow-up step. A NetworkPolicy that blocks port 53 is another cause to rule out.