What Is CoreDNS? Kubernetes DNS Resolution and Troubleshooting
CoreDNS is a plugin-based DNS server commonly used in Kubernetes to answer cluster-internal names for Services and Pods and, depending on configuration, forward other queries to upstream DNS resolvers. It is not the Kubernetes DNS API, and a Service named `kube-dns` does not prove that the kube-dns program is the backend. This guide describes a typical CoreDNS-backed cluster; domain suffixes, caches, and forwarding paths vary by distribution and configuration.
How a Pod name becomes an IP address
When a Pod looks up a name such as api.shop.svc.cluster.local, it usually sends the query to the cluster DNS Service IP listed in its /etc/resolv.conf. An ordinary Pod using the default dnsPolicy: ClusterFirst sends cluster-domain lookups to cluster DNS and external-domain lookups through the cluster DNS forwarding configuration. A different DNS policy or hostNetwork can change this path.
The DNS Service routes requests to CoreDNS Pods. CoreDNS's kubernetes plugin reads Kubernetes API data such as Services and EndpointSlices to answer for cluster domains. A regular ClusterIP Service can resolve to its service address; a headless Service can return endpoint addresses. The record depends on Service type and DNS rules. The forward plugin sends configured queries to upstream resolvers, while cache can retain responses within DNS TTL limits.
The path is: application → Pod resolv.conf → cluster DNS Service → CoreDNS → kubernetes plugin (cluster names) or forward plugin (upstream DNS) → response.
The kube-dns Service name may be retained for compatibility even when CoreDNS is the server. The DNS Service IP, CoreDNS Deployment, and configuration ConfigMap vary across managed services and installation methods. See Kubernetes DNS for Services and Pods and the CoreDNS kubernetes plugin.
CoreDNS, kube-dns, and plugins
Kubernetes specifies DNS-based service discovery behavior but does not require one DNS server implementation. CoreDNS is commonly deployed as a replacement for kube-dns and may serve behind the existing kube-dns Service address. Inspect the actual DNS Pods and configuration instead of inferring the software from the Service name.
CoreDNS behavior comes from server blocks and plugin chains in the Corefile. The kubernetes plugin serves cluster zones; forward sends matching queries upstream; cache caches responses; and loop can detect some simple forwarding loops at startup. Not every installation uses the same Corefile, plugins, or upstream resolvers. Check the CoreDNS plugin documentation for the plugins included and configured in your build.
Where to look when resolution fails
Separate the path into the Pod, DNS Service, CoreDNS processing, and upstream forwarding. These are read-oriented checks; names and labels vary by cluster. If you lack permissions, ask the cluster administrator for the observations.
Inspect `/etc/resolv.conf` in the failing Pod and its `dnsPolicy`, `dnsConfig`, and `hostNetwork` settings. Confirm the expected policy, nameserver, search domains, and `ndots` option. Compare the failing short name with its fully qualified domain name (FQDN) before changing settings.
Query different name scopes separately: a local Service name and FQDN, a Service in another namespace, and an external domain. For example: `kubectl exec -n <namespace> <pod> -- nslookup kubernetes.default.svc.cluster.local`. If `nslookup` is absent, use an existing DNS tool or an approved diagnostic Pod image; follow the cluster's image and network policies.
Find the cluster DNS Service and check whether it has ready backends. Inspect the DNS Service in `kube-system`, then the relevant EndpointSlices or the endpoint resource used by the cluster. A wrong Service IP or no ready endpoints may indicate selector, Pod readiness, or installation issues rather than a CoreDNS query problem.
Inspect CoreDNS Pod status and Events. With permission, `kubectl get pods -n kube-system -l k8s-app=kube-dns` and `kubectl logs -n kube-system deploy/coredns` can be starting points; adapt labels and names to the actual deployment. For `CrashLoopBackOff`, inspect previous-container logs, Corefile syntax, upstream addresses, permissions, and resource constraints.
If cluster names work but external names fail, inspect Corefile `forward` targets, reachability to upstream resolvers, network policy/firewall, and DNS response codes. If a query works from a CoreDNS Pod but fails only in one application Pod, examine that Pod's DNS policy, network path, or node-local cache. A forwarding loop can happen when an upstream points back to CoreDNS.
Before changing configuration, save the current ConfigMap or managed settings. Change one identified cause, verify rollout and Events, and repeat the same queries through the same namespace and path. Avoid deleting all DNS Pods at once or changing upstreams without a rollback plan.
For example, if kubernetes.default resolves but public domains fail, investigate external forwarding before Kubernetes record creation. If external names resolve but a Service FQDN does not, check the Kubernetes plugin's API access, Service name/namespace, and DNS Service path. This illustrates a diagnostic branch; it is not a reported cluster test.
Cache and forwarding-loop caveats
DNS cache avoids querying an upstream or data source for every request, but a changed record may not be visible until its TTL expires. A configured cache maximum caps retention; it does not extend a record beyond its own TTL. If an old IP appears after changing a Service, identify which cache layer served it and check the record TTL. A Pod or node-local cache may differ from CoreDNS's cache. CoreDNS cache plugin
A forwarding loop occurs if CoreDNS forwards to itself or an upstream sends the query back to CoreDNS. The loop plugin can detect simple loops at startup and halt the server, but it is not a universal detector for every possible cycle. For Loop ... detected and CrashLoopBackOff, inspect Corefile forwarding targets, the node's /etc/resolv.conf, and any local DNS cache. Fix the circular path and configure a real upstream; do not remove detection as a substitute. CoreDNS loop and forward plugins.
Changing CoreDNS safely
Record the failing domain scope, affected Pods/nodes, and DNS response code first. Inspect only the relevant kubernetes, forward, or cache settings rather than replacing the entire Corefile. Verify that forwarding zones and fallthrough behavior do not send internal names outside the cluster. A very long cache TTL delays changes; a very short TTL can increase upstream traffic. Choose values based on query load, data-change patterns, and resolver capacity.
Managed Kubernetes services may restrict direct edits or use an add-on manager. Use the provider-supported configuration and rollback path. After a change, verify an in-cluster Service name, a cross-namespace Service name, an external domain, and the recovery path.
Sources
[Kubernetes DNS for Services and Pods](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/)
[Customizing Kubernetes DNS service](https://kubernetes.io/docs/tasks/administer-cluster/dns-custom-nameservers/)
[CoreDNS kubernetes plugin](https://coredns.io/plugins/kubernetes/)
[CoreDNS forward plugin](https://coredns.io/plugins/forward/)
[CoreDNS cache plugin](https://coredns.io/plugins/cache/)
[CoreDNS loop plugin](https://coredns.io/plugins/loop/)