CoreDNS
Kubernetes
Cluster Management
Cache Flush
Networking

How to flush the CoreDNS cache on a Kubernetes cluster

Codemia Knowledge Hub ·

There is no "flush cache" command for CoreDNS in kubectl. Each CoreDNS pod keeps its own in-memory cache, so the practical way to clear it is to restart the pods with kubectl -n kube-system rollout restart deployment/coredns. The new pods start with empty caches.

Why there is no single cache to flush

CoreDNS caches DNS answers in memory so repeated lookups are fast and upstream resolvers do less work. During debugging, that cache can hide recent changes until the cached records expire.

CoreDNS usually runs as a Deployment in the kube-system namespace, and each pod has its own cache:

  • with two CoreDNS replicas, each holds its own cached answers
  • clearing one pod does not clear the others
  • restarting the pods is the normal way to clear cached entries

Restart the CoreDNS Deployment

bash
kubectl -n kube-system rollout restart deployment/coredns
kubectl -n kube-system rollout status deployment/coredns

This is the simplest and safest path because Kubernetes handles the pod replacement. Restarting only one pod in a multi-replica setup can leave stale answers on the others.

If you are not sure what the DNS component is called in your cluster, look first:

bash
kubectl -n kube-system get deploy,pods | grep -i dns

Some environments use different names, and managed clusters may add extra DNS components around CoreDNS.

Check the cache TTL in the Corefile

Recurring stale answers are often a TTL problem. The cache plugin is configured in the CoreDNS Corefile, which typically lives in a ConfigMap:

bash
kubectl -n kube-system get configmap coredns -o yaml

A common configuration contains a line such as:

txt
cache 30

That value controls how long answers may stay cached. If the cluster keeps serving stale answers longer than expected, tuning this duration is better than restarting DNS every time.

Test DNS from inside the cluster

Test before and after the restart from inside the cluster, so you check the same network path your workloads use:

bash
kubectl run dns-test --rm -it --restart=Never \
  --image=busybox:1.36 -- nslookup kubernetes.default.svc.cluster.local

For an external lookup:

bash
kubectl run dns-test --rm -it --restart=Never \
  --image=busybox:1.36 -- nslookup example.com

Testing from a workstation outside the cluster bypasses the in-cluster DNS path entirely.

When stale answers survive a restart

Then the CoreDNS cache is probably not the cause. Other layers can hold DNS state:

  • the application runtime may cache lookups
  • a node-local DNS layer may still hold old answers
  • the upstream DNS server may still serve the old record
  • the Kubernetes Service or Endpoints data may not have updated yet

Restarting CoreDNS clears CoreDNS memory, not every cache in the system.

Restarting CoreDNS in production

A restart is usually low risk in a healthy cluster, but it is still a control-plane networking action. Do it deliberately, watch the rollout, and confirm the pods are ready before assuming DNS is stable. If stale answers keep coming back, fix TTLs, upstream DNS or application caching instead of making restarts routine.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design