IPVS mode NodeLocal DNSCache

Jbn1233
1 min readOct 12, 2020

--

Reduce cluster DNS load by adding NodeLocal DNSCache on every node.

#!/bin/bash
cd $(dirname $0)
wget -q -O nodelocaldns.yaml https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/dns/nodelocaldns/nodelocaldns.yaml
kubedns=$(kubectl get svc kube-dns -n kube-system -o jsonpath={.spec.clusterIP})
domain=cluster.local
localdns=169.254.20.53
echo ""
echo kubedns=$kubedns
echo domain=$domain
echo localdns=$localdns
echo ""
echo -n "Continue ?"
read a
cat << EOF > run.sh
#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
sed "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
rm -rf \$0
EOF
bash ./run.sh > nodelocaldns_deploy.yaml
  • Remove excess comma on line: 146 and run
kubectl apply-f nodelocaldns_ipvs_ready.yaml
  • Update kubelet configuration file: /var/lib/kubelet/config.yaml on every node
clusterDNS:
- 169.254.20.53
  • Restart kubelet or restart just node
$ kubectl get ds -n kube-system 
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE
kube-proxy 4 4 4 4 4
node-local-dns 4 4 4 4 4
weave-net 4 4 4 4 4

Done.
refer : https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/

edit1: fixed error on the script, can not recall why I did it wrong way.

--

--

Jbn1233
Jbn1233

Written by Jbn1233

Very short and simple notes for CKA/SRE and may not works on your environment | jbn1233@gmail.com | Bangkok, Thailand |

No responses yet