Kubernetes DNS在pod中失败但在Docker容器中有效

时间:2017-10-22 21:57:47

标签: kubernetes

与我在Kubernetes主机上的Docker不同,nslookup google.com在我的Kubernetes pod中失败 - 更重要的是,nslookup kubernetes也是如此。有什么想法吗?相关信息如下。

kubectl version
Client Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.5", GitCommit:"17d7182a7ccbb167074be7a87f0a68bd00d58d97", GitTreeState:"clean", BuildDate:"2017-08-31T09:14:02Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"7", GitVersion:"v1.7.9", GitCommit:"19fe91923d584c30bd6db5c5a21e9f0d5f742de8", GitTreeState:"clean", BuildDate:"2017-10-19T16:55:06Z", GoVersion:"go1.8.3", Compiler:"gc", Platform:"linux/amd64"}

[root@masterk ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

[root@masterk ~]# cat /etc/resolv.conf
search company.com
nameserver 192.168.1.254

# flannel
[root@masterk ~]# kubectl describe  --namespace=kube-system cm kube-flannel-cfg
Name:           kube-flannel-cfg
Namespace:      kube-system
Labels:         app=flannel
                tier=node
Annotations:    kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","data":{"cni-conf.json":"{\n  \"name\": \"cbr0\",\n  \"type\": \"flannel\",\n  \"delegate\": {\n    \"isDefaultGateway\": true\n  }\...

Data
====
cni-conf.json:
----
{
  "name": "cbr0",
  "type": "flannel",
  "delegate": {
    "isDefaultGateway": true
  }
}

net-conf.json:
----
{
  "Network": "10.244.0.0/16",
  "Backend": {
    "Type": "vxlan"
  }
}

Events: <none>
"

[root@masterk ~]# ping google.com
PING google.com (216.58.192.206) 56(84) bytes of data.

[root@masterk ~]# docker run -ti busybox /bin/sh
/ # nslookup google.com
Server:    192.168.1.254
Address 1: 192.168.1.254 server.local

Name:      google.com
Address 1: 2607:f8b0:4009:80e::200e ord30s25-in-x0e.1e100.net
Address 2: 216.58.192.206 ord30s25-in-f206.1e100.net

[root@masterk ~]# kubectl exec -ti busybox -- /bin/sh
/ # nslookup google.com
Server:    10.96.0.10
Address 1: 10.96.0.10
nslookup: can't resolve 'google.com'

/ # nslookup kubernetes
Server:    10.96.0.10
Address 1: 10.96.0.10

nslookup: can't resolve 'kubernetes'


/ # cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local mycompany.com
options ndots:5

/ # ip route
default via 10.244.3.1 dev eth0
10.244.0.0/16 via 10.244.3.1 dev eth0
10.244.3.0/24 dev eth0 proto kernel scope link src 10.244.3.4


[root@masterk]# kubectl get pods --namespace=kube-system -l k8s-app=kube-dns
NAME                        READY     STATUS    RESTARTS   AGE
kube-dns-2425271678-nt31m   3/3       Running   3          2h

[root@masterk ]# kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name) -c kubedns
I1022 21:06:23.810037       6 dns.go:48] version: 1.14.3-4-gee838f6
I1022 21:06:23.812271       6 server.go:70] Using configuration read from directory: /kube-dns-config with period 10s
I1022 21:06:23.812306       6 server.go:113] FLAG: --alsologtostderr="false"
I1022 21:06:23.812313       6 server.go:113] FLAG: --config-dir="/kube-dns-config"
I1022 21:06:23.812317       6 server.go:113] FLAG: --config-map=""
I1022 21:06:23.812320       6 server.go:113] FLAG: --config-map-namespace="kube-system"
I1022 21:06:23.812323       6 server.go:113] FLAG: --config-period="10s"
I1022 21:06:23.812327       6 server.go:113] FLAG: --dns-bind-address="0.0.0.0"
I1022 21:06:23.812329       6 server.go:113] FLAG: --dns-port="10053"
I1022 21:06:23.812334       6 server.go:113] FLAG: --domain="cluster.local."
I1022 21:06:23.812338       6 server.go:113] FLAG: --federations=""
I1022 21:06:23.812342       6 server.go:113] FLAG: --healthz-port="8081"
I1022 21:06:23.812344       6 server.go:113] FLAG: --initial-sync-timeout="1m0s"
I1022 21:06:23.812347       6 server.go:113] FLAG: --kube-master-url=""
I1022 21:06:23.812371       6 server.go:113] FLAG: --kubecfg-file=""
I1022 21:06:23.812374       6 server.go:113] FLAG: --log-backtrace-at=":0"
I1022 21:06:23.812379       6 server.go:113] FLAG: --log-dir=""
I1022 21:06:23.812382       6 server.go:113] FLAG: --log-flush-frequency="5s"
I1022 21:06:23.812385       6 server.go:113] FLAG: --logtostderr="true"
I1022 21:06:23.812388       6 server.go:113] FLAG: --nameservers=""
I1022 21:06:23.812390       6 server.go:113] FLAG: --stderrthreshold="2"
I1022 21:06:23.812393       6 server.go:113] FLAG: --v="2"
I1022 21:06:23.812396       6 server.go:113] FLAG: --version="false"
I1022 21:06:23.812401       6 server.go:113] FLAG: --vmodule=""
I1022 21:06:23.812452       6 server.go:176] Starting SkyDNS server (0.0.0.0:10053)
I1022 21:06:23.812692       6 server.go:198] Skydns metrics enabled (/metrics:10055)
I1022 21:06:23.812701       6 dns.go:147] Starting endpointsController
I1022 21:06:23.812705       6 dns.go:150] Starting serviceController
I1022 21:06:23.812915       6 logs.go:41] skydns: ready for queries on cluster.local. for tcp://0.0.0.0:10053 [rcache 0]
I1022 21:06:23.812922       6 logs.go:41] skydns: ready for queries on cluster.local. for udp://0.0.0.0:10053 [rcache 0]
I1022 21:06:24.312871       6 dns.go:171] Initialized services and endpoints from apiserver
I1022 21:06:24.312904       6 server.go:129] Setting up Healthz Handler (/readiness)
I1022 21:06:24.312911       6 server.go:134] Setting up cache handler (/cache)
I1022 21:06:24.312916       6 server.go:120] Status HTTP port 8081

[root@masterk ]# kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name) -c dnsmasq
I1022 21:06:24.134376      18 main.go:76] opts: {{/usr/sbin/dnsmasq [-k --cache-size=1000 --log-facility=- --server=/cluster.local/127.0.0.1#10053 --server=/in-addr.arpa/127.0.0.1#10053 --server=/ip6.arpa/127.0.0.1#10053] true} /etc/k8s/dns/dnsmasq-nanny 10000000000}
I1022 21:06:24.134457      18 nanny.go:86] Starting dnsmasq [-k --cache-size=1000 --log-facility=- --server=/cluster.local/127.0.0.1#10053 --server=/in-addr.arpa/127.0.0.1#10053 --server=/ip6.arpa/127.0.0.1#10053]
I1022 21:06:24.155185      18 nanny.go:111]
W1022 21:06:24.155200      18 nanny.go:112] Got EOF from stdout
I1022 21:06:24.155215      18 nanny.go:108] dnsmasq[30]: started, version 2.76 cachesize 1000
I1022 21:06:24.155220      18 nanny.go:108] dnsmasq[30]: compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth no-DNSSEC loop-detect inotify
I1022 21:06:24.155225      18 nanny.go:108] dnsmasq[30]: using nameserver 127.0.0.1#10053 for domain ip6.arpa
I1022 21:06:24.155228      18 nanny.go:108] dnsmasq[30]: using nameserver 127.0.0.1#10053 for domain in-addr.arpa
I1022 21:06:24.155231      18 nanny.go:108] dnsmasq[30]: using nameserver 127.0.0.1#10053 for domain cluster.local
I1022 21:06:24.155235      18 nanny.go:108] dnsmasq[30]: reading /etc/resolv.conf
I1022 21:06:24.155237      18 nanny.go:108] dnsmasq[30]: using nameserver 127.0.0.1#10053 for domain ip6.arpa
I1022 21:06:24.155240      18 nanny.go:108] dnsmasq[30]: using nameserver 127.0.0.1#10053 for domain in-addr.arpa
I1022 21:06:24.155242      18 nanny.go:108] dnsmasq[30]: using nameserver 127.0.0.1#10053 for domain cluster.local
I1022 21:06:24.155246      18 nanny.go:108] dnsmasq[30]: using nameserver 192.168.1.254#53
I1022 21:06:24.155303      18 nanny.go:108] dnsmasq[30]: read /etc/hosts - 7 addresses

[root@masterk ]# kubectl logs --namespace=kube-system $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name) -c sidecar
ERROR: logging before flag.Parse: I1022 21:06:24.407699      31 main.go:48] Version v1.14.3-4-gee838f6
ERROR: logging before flag.Parse: I1022 21:06:24.407779      31 server.go:45] Starting server (options {DnsMasqPort:53 DnsMasqAddr:127.0.0.1 DnsMasqPollIntervalMs:5000 Probes:[{Label:kubedns Server:127.0.0.1:10053 Name:kubernetes.default.svc.cluster.local. Interval:5s Type:1} {Label:dnsmasq Server:127.0.0.1:53 Name:kubernetes.default.svc.cluster.local. Interval:5s Type:1}] PrometheusAddr:0.0.0.0 PrometheusPort:10054 PrometheusPath:/metrics PrometheusNamespace:kubedns})
ERROR: logging before flag.Parse: I1022 21:06:24.407824      31 dnsprobe.go:75] Starting dnsProbe {Label:kubedns Server:127.0.0.1:10053 Name:kubernetes.default.svc.cluster.local. Interval:5s Type:1}
ERROR: logging before flag.Parse: I1022 21:06:24.408243      31 dnsprobe.go:75] Starting dnsProbe {Label:dnsmasq Server:127.0.0.1:53 Name:kubernetes.default.svc.cluster.local. Interval:5s Type:1}

[root@masterk ]# kubectl get svc --namespace=kube-system
NAME       CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
kube-dns   10.96.0.10   <none>        53/UDP,53/TCP   2h

[root@masterk ]# kubectl get ep kube-dns --namespace=kube-system
NAME       ENDPOINTS                     AGE
kube-dns   10.244.0.3:53,10.244.0.3:53   2h

1 个答案:

答案 0 :(得分:0)

这对我有用:

console.log

来自:https://github.com/kubernetes/kubernetes/issues/45022