系统:Ubuntu 18.04.02
K8s版本:1.13.4
故障现象:安装KubeDNS后,Pod内无法ping通外网域名,访问外网IP、K8s内部域名或者IP均正常。
原因分析,查看Pod中的resolv.conf:
kubectl exec busybox -- cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
10.96.0.10为KubeDNS的集群IP,对于内部域名,KubeDNS会直接解析,对于外部域名,KubeDNS会丢给上一级DNS服务器解析,这个上一级DNS服务器就依赖于resolv.conf。
查看KubeDNS Pod中的resolv.conf:
kubectl -n kube-system exec kube-dns-57f56f74cb-s86k7 -- cat /etc/resolv.conf
Defaulting container name to kubedns.
Use 'kubectl describe pod/kube-dns-57f56f74cb-s86k7 -n kube-system' to see all of the containers in this pod.
nameserver 127.0.0.53
options edns0
查看宿主机(Node或Master)该文件,cat /etc/resolv.conf:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting loca