【问题标题】:Curl cant resolve host with kubernetes dnsCurl 无法使用 kubernetes dns 解析主机
【发布时间】:2021-08-18 14:53:15
【问题描述】:

您好,我在 kubernetes 中遇到了问题。当我从一个 pod 进行 nslookup 时,我得到了正确的 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 是正确的 ip,但是当我尝试从同一命名空间中的 pod 卷曲这个 DNS 时,我得到了这个:

~ 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 使用以下 yaml 启动:

apiVersion: v1
kind: Pod
metadata:
  name: curl
  namespace: risk
spec:
  containers:
  - image: curlimages/curl
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: curl
  restartPolicy: Always

【问题讨论】:

  • curl pod 中的 /etc/resolv.conf 是什么?
  • search exampleNamespace.svc.cluster.local svc.cluster.local cluster.local c.-redacted-.internal google.internal nameserver 192.168.3.10 options ndots:5 是 resolv.conf 的输出的卷曲荚。 :)
  • 感谢大家的帮助,最终使用 buildpack-deps:curl 而不是 curlimages/curl 解决了这个问题。我运行了 k exec -it curl -- cat /etc/nsswitch.conf ,但我只是得到“cat: can't open '/etc/nsswitch.conf': No such file or directory”

标签: kubernetes curl dns


【解决方案1】:

据一些网站报道,AlpineKubernetes dns 解析存在一些问题:

使用图片curlimages/curl:7.77.0 可以正常工作。

【讨论】:

    【解决方案2】:

    原来将图像从 curlimages/curl 交换到 buildpack-deps:curl 解决了这个问题,但我不知道为什么。

    工作 yaml:

    apiVersion: v1
    kind: Pod
    metadata:
      name: curl
      namespace: risk
    spec:
      containers:
      - image: buildpack-deps:curl
        command:
          - sleep
          - "3600"
        imagePullPolicy: IfNotPresent
        name: curl
      restartPolicy: Always
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-12
      • 1970-01-01
      • 2020-03-15
      相关资源
      最近更新 更多