Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flush CoreDNS Cache on Kubernetes Cluster

How to flush CoreDNS Cache on kubernetes cluster?

I know it can be done by deleting the CoreDNS pods, but is there a proper way to to the cache flush ?

like image 642
Fauzan Avatar asked Feb 26 '19 04:02

Fauzan


People also ask

Does Kubernetes use CoreDNS?

Like Kubernetes, the CoreDNS project is hosted by the CNCF. You can use CoreDNS instead of kube-dns in your cluster by replacing kube-dns in an existing deployment, or by using tools like kubeadm that will deploy and upgrade the cluster for you.

Does CoreDNS cache?

With cache enabled, all records except zone transfers and metadata records will be cached for up to 3600s.

Does Kubernetes have cache?

Kubernetes itself doesn't cache the images, it is the underlying OCI runtime that does the caching.


2 Answers

@coollinuxoid's answer is not suitable for production environment, it will have temporary downtime because the commands will terminate all pods at the same time. Instead, you should use kubernetes deployment's rolling update mechanism by setting an environment variable to avoid the downtime with command:

kubectl -n kube-system set env deployment.apps/coredns FOO="BAR"
like image 195
Tony Lee Avatar answered Oct 04 '22 19:10

Tony Lee


The best way, as you said, would be restarting coredns pods. This can be done easily, by scaling the coredns deployment to "0" and then, scale it back to the desired number. Like in the sample command below:

kubectl scale deployment.apps/coredns -n kube-system --replicas=0
kubectl scale deployment.apps/coredns -n kube-system --replicas=2
like image 24
coolinuxoid Avatar answered Oct 04 '22 19:10

coolinuxoid