14

I am trying to learn DNS in kubernetes with https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/

  1. I deployed the busybox

  2. kubectl get pods busybox -o wide

    NAME      READY     STATUS    RESTARTS   AGE       IP           NODE
    busybox   1/1       Running   0          16m       10.200.1.5   worker-1
    
  3. kubectl exec -ti busybox -- nslookup kubernetes.default

    Server:    10.32.0.10
    Address 1: 10.32.0.10 kube-dns.kube-system.svc.cluster.local
    
    nslookup: can't resolve 'kubernetes.default'
    command terminated with exit code 1
    
  4. Do I need to modify the /etc/resolv.conf file of the worker-1 node. currently the /etc/resolv.conf content is below

    nameserver 169.254.169.254
    search c.k8s-project-193906.internal google.internal**
    
  5. Also the version of the worker-1 lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.1 LTS Release: 18.04 Codename: bionic

Please help me figure out which configuration causes the resolve error. Do I need to change resolve.conf file and based on what?

Nic3500
  • 8,144
  • 10
  • 29
  • 40
talktolanka
  • 189
  • 1
  • 2
  • 4
  • Can you please provide some more information on where do you try to do that? Is this somewhere in the Cloud (if yes which one) or on-premise Kubernetes? I can tell it is not a minikube so what tool did you use to deploy the cluster? – aurelius Aug 31 '18 at 14:28

2 Answers2

20

You have encountered a bug in the latest versions of the busybox docker image. Use the tag busybox:1.28 instead of latest. This bug link is here:

"Nslookup does not work in latest busybox image"
"1.27/1.28 are working , 1.29/1.29.1 are not"

Here it is failing with the busybox:latest tag.

$ kubectl run busybox --image busybox:latest --restart=Never --rm -it busybox -- sh
If you don't see a command prompt, try pressing enter.
/ # nslookup kubernetes.default
Server:         10.96.0.10
Address:        10.96.0.10:53

** server can't find kubernetes.default: NXDOMAIN

*** Can't find kubernetes.default: No answer
/ # exit
pod "busybox" deleted

Here's the same command succeeding with the busybox:1.28 tag.

$ kubectl run busybox --image busybox:1.28 --restart=Never --rm -it busybox -- sh
If you don't see a command prompt, try pressing enter.
/ # nslookup kubernetes.default
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      kubernetes.default
Address 1: 10.96.0.1 kubernetes.default.svc.cluster.local
/ # exit
pod "busybox" deleted
David W
  • 1,021
  • 8
  • 6
  • nslookup for my service is working inside a busybox but its not working directly what is the reason?? @David – AATHITH RAJENDRAN Apr 22 '19 at 11:40
  • @DavidW: Thanks, man! I have googled for 2h hours about the error in DNS and found it in busybox. – Maxim Suslov Dec 16 '20 at 22:22
  • Running just nslookup inside pod terminal and hitting enter output busybox version 1.35. How can change that. I was trying to get DNS service discovery to work in minikube. – KnownUnknown Mar 18 '23 at 21:14
1

try this.

vagrant@kubemaster:~$ cat dnsutils.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: dnsutils
  namespace: default
spec:
  containers:
  - name: dnsutils
    image: gcr.io/kubernetes-e2e-test-images/dnsutils:1.3
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  restartPolicy: Always

save this in yaml format and run kubectl apply -f <filename>.yaml and then run below command

vagrant@kubemaster:~$ kubectl exec -i -t dnsutils -- nslookup 10-40-0-2.default.pod  | tee nginx-pod

Server:     10.96.0.10
Address:    10.96.0.10#53

Name:   10-40-0-2.default.pod.cluster.local
Address: 10.40.0.2

It should resolve the output and save it in the file.

Oli Girling
  • 605
  • 8
  • 14