2

Hello I have a problem in kubernetes. When I do a nslookup from a pod I get correct ip:

~ kubectl -n exampleNamespace exec -it pod/curl -- nslookup exampleService.exampleNamespace
Defaulting container name to curl.
Use 'kubectl describe pod/curl -n exampleNamespace' to see all of the containers in this pod.
Server:     192.168.3.10
Address:    192.168.3.10:53

** server can't find exampleService.exampleNamespace: NXDOMAIN

Non-authoritative answer:
Name:   exampleService.exampleNamespace
Address: 192.168.3.64

command terminated with exit code 1

192.168.3.64 is the correct ip but when I try to curl this DNS from a pod in the same namespace I get this:

~ kubectl -n exampleNamespace exec -it pod/curl -- curl http://exampleService.exampleNamespace/path
Defaulting container name to curl.
Use 'kubectl describe pod/curl -n exampleNamespace' to see all of the containers in this pod.
curl: (6) Could not resolve host: exampleService.exampleNamespace
command terminated with exit code 6

Curl pod was started with following yaml:

apiVersion: v1
kind: Pod
metadata:
  name: curl
  namespace: exampleNamespace
spec:
  containers:
  - image: curlimages/curl
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: curl
  restartPolicy: Always
D. O.
  • 109
  • 2
  • 9
  • 1
    what is the /etc/resolv.conf in the curl pod? – Hugo Aug 18 '21 at 15:13
  • 1
    You can try to debug with https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/ – Hugo Aug 18 '21 at 15:20
  • search exampleNamespace.svc.cluster.local svc.cluster.local cluster.local c.-redacted-.internal google.internal nameserver 192.168.3.10 options ndots:5 is the output of the resolv.conf of the curl pod. :) – D. O. Aug 18 '21 at 16:07
  • Thanks for the help guys, in the end it turns out using buildpack-deps:curl instead of curlimages/curl solved the issue. I ran k exec -it curl -- cat /etc/nsswitch.conf anyways, but I just got "cat: can't open '/etc/nsswitch.conf': No such file or directory" – D. O. Aug 18 '21 at 17:17

2 Answers2

3

It seams that there are some problems with Alpine and Kubernetes dns resolution as reported at some sites:

Using image curlimages/curl:7.77.0 works as expected.

apiVersion: v1
kind: Pod
metadata:
  name: curl
  namespace: exampleNamespace
spec:
  containers:
  - image: curlimages/curl:7.77.0
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: curl
  restartPolicy: Always
TlmaK0
  • 3,578
  • 2
  • 31
  • 51
0

Turns out swapping the image from curlimages/curl to buildpack-deps:curl solved the issue, I don't know why though.

Working yaml:

apiVersion: v1
kind: Pod
metadata:
  name: curl
  namespace: exampleNamespace
spec:
  containers:
  - image: buildpack-deps:curl
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: curl
  restartPolicy: Always
D. O.
  • 109
  • 2
  • 9