Reduce cluster DNS load by adding NodeLocal DNSCache on every node.
- Download template file from:
https://github.com/kubernetes/kubernetes/blob/master/cluster/addons/dns/nodelocaldns/nodelocaldns.yaml - Create this bash script (don’t forget to change kubedns,domain,localdns variables)
#!/bin/bash
cd $(dirname $0)
wget -q -O nodelocaldns.yaml https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/dns/nodelocaldns/nodelocaldns.yamlkubedns=$(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 acat << 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.