Cloud Native 6 min read

Deploying NodeLocal DNSCache to Improve DNS Resolution in Kubernetes Clusters

This article explains the NodeLocal DNSCache solution for Kubernetes, describing how it reduces CoreDNS load, improves DNS query performance, and provides step‑by‑step deployment instructions with configuration examples and command‑line snippets for both IPTABLES and IPVS proxy modes.

DevOps Operations Practice
DevOps Operations Practice
DevOps Operations Practice
Deploying NodeLocal DNSCache to Improve DNS Resolution in Kubernetes Clusters

During the operation of a Kubernetes (K8s) cluster, some Pods may experience request timeouts when resolving Service names. This occurs because DNS queries from Pods are handled by CoreDNS, which can become a bottleneck in large‑scale clusters.

The Kubernetes community introduced the NodeLocal DNSCache solution to enhance DNS resolution performance by deploying a DNS cache on each node using a DaemonSet, thereby offloading CoreDNS and reducing network latency for Pods.

1. Solution Overview

NodeLocal DNSCache runs a DNS caching service on every node, avoiding cross‑node network hops and alleviating CoreDNS pressure. After enabling it, DNS queries follow a flow where cached responses are served locally, and only uncached queries are forwarded to CoreDNS.

2. Deploy NodeLocal DNSCache

1. Create a resource manifest named nodelocaldns.yaml (example can be found at GitHub ).

2. Modify the manifest variables to match your environment:

kubedns=`kubectl get svc kube-dns -n kube-system -o jsonpath={.spec.clusterIP}`

domain=<cluster-domain>
localdns=<node-local-address>

# Example values

domain=cluster.local
localdns=169.254.20.10

3. Adjust settings based on the kube‑proxy mode:

If kube‑proxy runs in IPTABLES mode, execute: sed -i "s/__PILLAR__LOCAL__DNS__/$localdns/g; s/__PILLAR__DNS__DOMAIN__/$domain/g; s/__PILLAR__DNS__SERVER__/$kubedns/g" nodelocaldns.yaml

If kube‑proxy runs in IPVS mode, execute: sed -i "s/__PILLAR__LOCAL__DNS__/$localdns/g; s/__PILLAR__DNS__DOMAIN__/$domain/g; s/,__PILLAR__DNS__SERVER__//g; s/__PILLAR__CLUSTER__DNS__/$kubedns/g" nodelocaldns.yaml

4. Deploy the manifest:

kubectl create -f nodelocaldns.yaml

After deployment, the node‑local‑dns Pods run in the kube-system namespace on each node.

$ kubectl get pod -n kube-system -l k8s-app=node-local-dns
NAME                     READY   STATUS    RESTARTS   AGE
node-local-dns-clrsb     1/1     Running   0          6m35s
node-local-dns-msx22    1/1     Running   0          6m35s
node-local-dns-wpphv     1/1     Running   0          6m35s

If using IPVS mode, update each node’s kubelet --cluster-dns flag to point to the local DNS address, then reload and restart the kubelet:

sed -i 's/$kubedns/$localdns/g' /var/lib/kubelet/config.yaml
systemctl daemon-reload && systemctl restart kubelet

Verify the new DNS configuration on a node:

$ cat /etc/resolv.conf
nameserver 169.254.20.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5

At this point, the deployment is complete and you can experience the performance benefits of NodeLocal DNSCache.

cloud nativeoperationsKubernetesClusterDNSNodeLocal DNSCache
DevOps Operations Practice
Written by

DevOps Operations Practice

We share professional insights on cloud-native, DevOps & operations, Kubernetes, observability & monitoring, and Linux systems.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.