'Curl cant resolve host with kubernetes dns
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
Solution 1:[1]
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
Solution 2:[2]
It seams that there are some problems with Alpine
and Kubernetes
dns resolution as reported at some sites:
- https://www.openwall.com/lists/musl/2018/03/30/9
- Does Alpine have known DNS issue within Kubernetes?
- https://github.com/gliderlabs/docker-alpine/issues/8
- https://github.com/kubernetes/kubernetes/issues/30215
Using image curlimages/curl:7.77.0
works as expected.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | TlmaK0 |