NodeLocal DNSCache通过在群集节点上运行DaemonSet的Pod来做dns缓存代理提高群集DNS性能。
在没有NodeLocal DNSCache的架构中,集群中的Pod默认ClusterFirst DNS模式中的可以访问kube-dns serviceIP以进行DNS查询。通过kube-proxy添加的iptables规则将其转换为kube-dns / CoreDNS端点。
在使用NodeLocal DNSCache的架构中,Pods将访问Pod所在的节点上运行的dns缓存代理,从而避免iptables DNAT和conntrack。Pod在查询集群中主机名的缓存未命中情况下 DNS缓存代理将查询kube-dns服务(默认cluster_domain为cluster.local后缀)
nf_conntrack_udp_timeout
为30秒)此图显示了NodeLocal DNSCahe如何处理DNS查询。
curl -s -O https://raw.githubusercontent.com/kubernetes/kubernetes/master/cluster/addons/dns/nodelocaldns/nodelocaldns.yaml
#dnsPolicy: Default # Don't use cluster DNS.
sed -i -e "s/__PILLAR__DNS__DOMAIN__/${KUBE_DNS_NAME:-cluster.local.}/g" nodelocaldns.yaml
sed -i -e "s/__PILLAR__DNS__SERVER__/${KUBE_DNS_SERVER_IP:-10.68.0.2}/g" nodelocaldns.yaml
sed -i -e "s/__PILLAR__LOCAL__DNS__/${KUBE_LOCAL_DNS_IP:-169.254.20.10}/g" nodelocaldns.yaml
kubectl create -f nodelocaldns.yaml
//修改kubelet --cluster-dns=169.254.20.10
sed -i -e "s/--cluster-dns=${KUBE_DNS_SERVER_IP:-10.68.0.2}/--cluster-dns=${KUBE_LOCAL_DNS_IP:-169.254.20.10}/g" /etc/systemd/system/kubelet.service
systemctl daemon-reload
systemctl restart kubelet.service
k8s version | Feature support |
---|---|
1.15 | Beta(Not enabled by default) |
1.13 | Alpha(Not enabled by default) |
https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/
https://github.com/kubernetes/kubernetes/issues/56903
https://www.kernel.org/doc/Documentation/networking/nf_conntrack-sysctl.txt