k8s service discovery using DNS

12/8/2017

Recently, I found something interesting that I haven't seen b4. I'm using "kube-dns" for service discovery. If would imagine that all names (service-name.namespace.svc.cluster.local) should reflect the same IP for the nginx service (nginx-svc). But I noticed that dns query against 1) nginx-svc and 2) nginx-svc.default are different.

I create a service (called nginx-svc) and backed by nginx pod. If I got into nginx pod to run dns resolution it will be fine. If I run the busybox like below, it has issue with nginx-svc.default resolution. Don't know why? I would imagine it should work.

kubectl run -it --rm busybox --restart=Never --image=busybox sh

/ # nslookup nginx-svc
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      nginx-svc
Address 1: 10.97.174.54 nginx-svc.default.svc.cluster.local
/ # nslookup nginx-svc.default
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      nginx-svc.default
Address 1: 198.105.244.228
Address 2: 198.105.254.228
/ # exit

Any thoughts on this? Or, advice? Thanks

Also, for above nslookup im using busybox in the same namespace (which is "default") with nginx-svc.

/ # cat /etc/resolv.conf 
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
-- Fei
kubernetes

0 Answers