kube-dns: resolve <service name> success, resolve <service name>.<namespace> failed

6/28/2019

I deploy kube-dns successfully in my cluster. And the k8s official documents(https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/) says you could resolve three forms address:

  1. <service name>
  2. <service name>.<namespace>
  3. <service name>.<namespace>.svc.cluster.local

It's strange that I could nslookup 1&&3 in success, but failed on 2.

For example, we have a service called nginx in namespace default. And I execute following command on a pod also in namespace default:

  1. nslookup nginx
  2. nslookup nginx.default
  3. nslookup nginx.defaultsvc.cluster.local

1&&3 would be success, and 2 would be failed.

I logged the communication between two nodes: Say we have a pod called pod-src running on node-src. And we have dns pod running on node-dns. I execute tcpdump -i docker0 on node-dns, it looks like:

  1. nslookup kubernetes.default.svc.cluster.local

    15:08:01.714732 IP 172.30.102.0.44766 > 172.30.96.2.domain: 2+ PTR? 2.0.254.10.in-addr.arpa. (41)
    15:08:01.715317 IP 172.30.96.2.domain > 172.30.102.0.44766: 2 1/0/0 PTR kube-dns.kube-system.svc.cluster.local. (93)
    15:08:01.716090 IP 172.30.102.0.39995 > 172.30.96.2.domain: 3+ AAAA? kubernetes.default.svc.cluster.local. (54)
    15:08:01.716492 IP 172.30.96.2.domain > 172.30.102.0.39995: 3* 0/1/0 (108)
    15:08:01.717521 IP 172.30.102.0.46919 > 172.30.96.2.domain: 4+ A? kubernetes.default.svc.cluster.local. (54)
    15:08:01.717870 IP 172.30.96.2.domain > 172.30.102.0.46919: 4* 1/0/0 A 10.254.0.1 (70)
    15:08:01.718690 IP 172.30.102.0.35495 > 172.30.96.2.domain: 5+ PTR? 1.0.254.10.in-addr.arpa. (41)
    15:08:01.719088 IP 172.30.96.2.domain > 172.30.102.0.35495: 5 1/0/0 PTR kubernetes.default.svc.cluster.local. (91)

    2.nsklookup kubernetes.default

    15:08:06.677306 IP 172.30.102.0.59105 > 172.30.96.2.domain: 2+ PTR? 2.0.254.10.in-addr.arpa. (41)
    15:08:06.677410 IP 172.30.96.2.domain > 172.30.102.0.59105: 2 1/0/0 PTR kube-dns.kube-system.svc.cluster.local. (93)
    15:08:06.678175 IP 172.30.102.0.37486 > 172.30.96.2.domain: 3+ AAAA? kubernetes.default. (36)
    15:08:06.678468 IP 172.30.96.2.16854 > dns.localdns.com.domain: 31419+ AAAA? kubernetes.default. (36)
    15:08:06.678507 IP 172.30.96.2.16854 > 10.167.1.1.domain: 31419+ AAAA? kubernetes.default. (36)
    15:08:06.678873 IP dns.localdns.com.domain > 172.30.96.2.16854: 31419 0/1/0 (127)
    15:08:06.678886 IP 10.167.1.1.domain > 172.30.96.2.16854: 31419 0/1/0 (116)
    15:08:06.678978 IP 172.30.96.2.domain > 172.30.102.0.37486: 3 0/1/0 (127)
    15:08:06.680163 IP 172.30.102.0.46175 > 172.30.96.2.domain: 4+ A? kubernetes.default. (36)
    15:08:06.680319 IP 172.30.96.2.52575 > dns.localdns.com.domain: 53398+ A? kubernetes.default. (36)
    15:08:06.680573 IP dns.localdns.com.domain > 172.30.96.2.52575: 53398 0/1/0 (127)
    15:08:06.680694 IP 172.30.96.2.domain > 172.30.102.0.46175: 4 0/1/0 (127)
    1. nslookup kubernetes

      15:10:49.753009 IP 172.30.102.0.33202 > 172.30.96.2.domain: 2+ PTR? 2.0.254.10.in-addr.arpa. (41)
      15:10:49.753444 IP 172.30.96.2.domain > 172.30.102.0.33202: 2 1/0/0 PTR kube-dns.kube-system.svc.cluster.local. (93)
      15:10:49.754147 IP 172.30.102.0.38670 > 172.30.96.2.domain: 3+ AAAA? kubernetes.default.svc.cluster.local. (54)
      15:10:49.754527 IP 172.30.96.2.domain > 172.30.102.0.38670: 3* 0/1/0 (108)
      15:10:49.755278 IP 172.30.102.0.55790 > 172.30.96.2.domain: 4+ A? kubernetes.default.svc.cluster.local. (54)
      15:10:49.755648 IP 172.30.96.2.domain > 172.30.102.0.55790: 4* 1/0/0 A 10.254.0.1 (70)
      15:10:49.756342 IP 172.30.102.0.42938 > 172.30.96.2.domain: 5+ PTR? 1.0.254.10.in-addr.arpa. (41)
      15:10:49.756646 IP 172.30.96.2.domain > 172.30.102.0.42938: 5 1/0/0 PTR kubernetes.default.svc.cluster.local. (91)
      • 172.30.102.0 is the docker0 address in src-node.
      • 172.30.96.2 is the dns pod address.
      • 10.167.1.1 is the local name server.
      • dns.localdns.com is also our local name server.
-- wan linghao
kubernetes

0 Answers