Why dig does not resolve K8s service by dns name while nslookup has no problems with it?

6/3/2018

Here are steps to reproduce:

minikube start
kubectl run nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=ClusterIP

kubectl run -i --tty --rm alpine --image=alpine --restart=Never -- sh
apk add --no-cache bind-tools

Now let's try to query kibe-dns for nginx service

with nslookup:

/ # nslookup nginx.default 10.96.0.10
Server:     10.96.0.10
Address:    10.96.0.10#53

Name:   nginx.default.svc.cluster.local
Address: 10.97.239.175

and with dig:

dig nginx.default @10.96.0.10 any

; <<>> DiG 9.11.3 <<>> nginx.default @10.96.0.10 any
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46414
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;nginx.default.         IN  ANY

;; Query time: 279 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: Sun Jun 03 15:31:15 UTC 2018
;; MSG SIZE  rcvd: 42

Nothing changes if I replace name nginx.default with just nginx.

minikube version: v0.27.0, k8s version: 1.10.0

-- Kirill
dig
kube-dns
kubernetes
kubernetes-service
nslookup

1 Answer

6/3/2018

Few things to point out:

  1. Always use "nginx.default.svc.cluster.local", and don't rely on the tool to complete it for you.
  2. Run dig nginx.default.svc.cluster.local NS you will see there are no hosting nameserver for it. You can only specify one when there are at least one exists.
  3. Interestingly I found out that dig any in alpine doesn't really work so, so in this case, I am afraid that you have to explicitly use A or left it empty(A is default)

Conclusion:

Run dig nginx.default.svc.cluster.local or dig nginx.default.svc.cluster.local A instead.

-- John Hua
Source: StackOverflow