问题:
dns不通
[root@k8s-master ~]# kubectl exec -it busyboxx sh
/ # nslookup nginx
Server: 10.254.230.254
Address 1: 10.254.230.254
nslookup: can't resolve 'nginx'
/ # cat /etc/resolv.conf
search default.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.254.230.254
nameserver 8.8.8.8
options ndots:5
查看pod日志
[root@k8s-master ~]# kubectl logs -f kube-dns-3204099596-x7vdj -c kubedns -n kube-system
I0613 20:15:12.651122 1 dns.go:42] version: v1.6.0-alpha.0.680+3872cb93abf948-dirty
I0613 20:15:12.651262 1 server.go:107] Using http://192.168.150.61:8080 for kubernetes master, kubernetes API: v1
I0613 20:15:12.651550 1 server.go:68] Using configuration read from ConfigMap: kube-system:kube-dns
I0613 20:15:12.651599 1 server.go:113] FLAG: --alsologtostderr="false"
I0613 20:15:12.651613 1 server.go:113] FLAG: --config-map="kube-dns"
I0613 20:15:12.651620 1 server.go:113] FLAG: --config-map-namespace="kube-system"
I0613 20:15:12.651626 1 server.go:113] FLAG: --dns-bind-address="0.0.0.0"
I0613 20:15:12.651630 1 server.go:113] FLAG: --dns-port="10053"
I0613 20:15:12.651637 1 server.go:113] FLAG: --domain="cluster.local."
I0613 20:15:12.651645 1 server.go:113] FLAG: --federations=""
I0613 20:15:12.651651 1 server.go:113] FLAG: --healthz-port="8081"
I0613 20:15:12.651656 1 server.go:113] FLAG: --kube-master-url="http://192.168.150.61:8080"
I0613 20:15:12.651662 1 server.go:113] FLAG: --kubecfg-file=""
I0613 20:15:12.651666 1 server.go:113] FLAG: --log-backtrace-at=":0"
I0613 20:15:12.651673 1 server.go:113] FLAG: --log-dir=""
I0613 20:15:12.651679 1 server.go:113] FLAG: --log-flush-frequency="5s"
I0613 20:15:12.651685 1 server.go:113] FLAG: --logtostderr="true"
I0613 20:15:12.651691 1 server.go:113] FLAG: --stderrthreshold="2"
I0613 20:15:12.651695 1 server.go:113] FLAG: --v="0"
I0613 20:15:12.651700 1 server.go:113] FLAG: --version="false"
I0613 20:15:12.651707 1 server.go:113] FLAG: --vmodule=""
I0613 20:15:12.651756 1 server.go:155] Starting SkyDNS server (0.0.0.0:10053)
I0613 20:15:12.666762 1 server.go:165] Skydns metrics enabled (/metrics:10055)
I0613 20:15:12.669465 1 logs.go:41] skydns: ready for queries on cluster.local. for tcp://0.0.0.0:10053 [rcache 0]
I0613 20:15:12.669518 1 logs.go:41] skydns: ready for queries on cluster.local. for udp://0.0.0.0:10053 [rcache 0]
E0613 20:15:12.679738 1 sync.go:105] Error getting ConfigMap kube-system:kube-dns err: configmaps "kube-dns" not found
E0613 20:15:12.679763 1 dns.go:190] Error getting initial ConfigMap: configmaps "kube-dns" not found, starting with default values
I0613 20:15:12.684971 1 server.go:126] Setting up Healthz Handler (/readiness)
I0613 20:15:12.685000 1 server.go:131] Setting up cache handler (/cache)
I0613 20:15:12.685007 1 server.go:120] Status HTTP port 8081
解决:
[root@k8s-master ~]# cat kube-dns-cm.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: kube-dns
namespace: kube-system
data:
upstreamNameservers: |
["1.2.3.4"]
kubectl create -f kube-dns-cm.yml
重启kube.
[root@k8s-master ~]# kubectl get deploy,po,svc,cm,ep -n kube-system
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deploy/kube-dns 1 1 1 1 33m
NAME READY STATUS RESTARTS AGE
po/kube-dns-3204099596-n2w84 4/4 Unknown 0 33m
po/kube-dns-3204099596-x7vdj 4/4 Running 0 23m
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kube-dns 10.254.230.254 <none> 53/UDP,53/TCP 31m
NAME DATA AGE
cm/kube-dns 1 13m
NAME ENDPOINTS AGE
ep/kube-controller-manager <none> 25m
ep/kube-dns 10.0.55.7:53,10.0.55.7:53 31m
ep/kube-scheduler <none> 25m
再次 nslookup
[root@k8s-master ~]# kubectl exec -it busyboxx sh
/ # nslookup kubernetes
Server: 10.254.230.254
Address 1: 10.254.230.254 kube-dns.kube-system.svc.cluster.local
Name: kubernetes
Address 1: 10.254.0.1 kubernetes.default.svc.cluster.local
/ # nslookup nginx
Server: 10.254.230.254
Address 1: 10.254.230.254 kube-dns.kube-system.svc.cluster.local
Name: nginx
Address 1: 10.254.213.70 nginx.default.svc.cluster.local
参考
https://cloud.tencent.com/developer/article/1649590
https://www.thinbug.com/q/43240135