CoreDNS is one of those quiet heroes in your Kubernetes cluster. It doesn’t get much attention—until DNS stops working, and suddenly everything breaks.

Let’s understand how it works — simply.

What Is CoreDNS?

CoreDNS is the default DNS server in Kubernetes. It’s what helps your pods resolve names like my-service.default.svc.cluster.local to an actual IP address.

It’s not just a DNS server. It’s modular, pluggable, and built for cloud-native environments.

Why Is DNS Needed in Kubernetes?

In Kubernetes, everything is dynamic:

  • Pods come and go.
  • IPs change.
  • Services scale up and down.

You can’t rely on static IPs. Instead, DNS gives you a stable name, like my-db, and resolves it to the correct IP at runtime.

How CoreDNS Works

When a pod makes a DNS query:

  1. It goes to the cluster’s configured nameserver — CoreDNS.
  2. CoreDNS checks its configuration.
  3. If it can resolve the name (e.g., service name), it replies.
  4. If not, it may forward the request to an external DNS (like 8.8.8.8).

It uses a Corefile for configuration. Here’s a basic example:

.:53 {
  errors
  health
  kubernetes cluster.local in-addr.arpa ip6.arpa {
    pods insecure
    fallthrough in-addr.arpa ip6.arpa
  }
  forward . /etc/resolv.conf
  cache 30
  loop
  reload
  loadbalance
}

How to Check CoreDNS Logs

kubectl -n kube-system logs -l k8s-app=kube-dns

Common Issues

  • High DNS latency: Try enabling CoreDNS caching.
  • Loop errors: Happens if CoreDNS ends up querying itself.
  • Misconfigured Corefile: Always double-check your forward and kubernetes blocks.

Summary

CoreDNS is the backbone of service discovery in Kubernetes. Understanding how it works helps debug service connectivity issues and keep your apps running smoothly.

→ Learn more: