【问题标题】:Cannot access pod via pod IP from within the cluster, causing liveness / readiness probe failure无法从集群内通过 pod IP 访问 pod,导致 liveness/readiness 探测失败
【发布时间】:2019-07-20 14:59:43
【问题描述】:

一些简单的背景知识:在 golang 中创建一个应用程序,在 MacOS 10.14.2 上的 minikube 上运行

karlewr [0] $ kubectl version
Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.1", GitCommit:"b1b29978270dc22fecc592ac55d903350454310a", GitTreeState:"clean", BuildDate:"2018-07-18T11:37:06Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"12", GitVersion:"v1.12.4", GitCommit:"f49fa022dbe63faafd0da106ef7e05a29721d3f1", GitTreeState:"clean", BuildDate:"2018-12-14T06:59:37Z", GoVersion:"go1.10.4", Compiler:"gc", Platform:"linux/amd64"}

问题: 我无法通过集群内部的 pod IP 访问我的 pod。这个问题只发生在这个 pod 上,这让我相信我在某处有错误配置。

我的 pod 规格如下:

containers:
  - name: {{ .Chart.Name }}
    image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
    ports:
      - name: http
        containerPort: 8080
        protocol: TCP
    livenessProbe:
      httpGet:
        path: /ping
        port: 8080
      initialDelaySeconds: 60
    readinessProbe:
      httpGet:
        path: /ping
        port: 8080
      initialDelaySeconds: 60

奇怪的是,我可以通过在端口 8080 上转发该 pod 并在 liveness 和 readiness 探针运行之前以及在 pod 初始化之后运行 curl localhost:8080/ping 来访问它。这将返回 200 OK。

同样在 CrashLoopBackoff 之前的这段时间内,如果我 ssh 进入我的 minikube 节点并运行 curl http://172.17.0.21:8080/ping 我会得到 curl: (7) Failed to connect to 172.17.0.21 port 8080: Connection refused。使用的 IP 是我的 pod 的 IP。

但是当我在initialDelaySeconds 期间之后描述 pod 时,我看到了这个:

  Warning  Unhealthy  44s (x3 over 1m)  kubelet, minikube  Readiness probe failed: Get http://172.17.0.21:8080/ping: dial tcp 172.17.0.21:8080: connect: connection refused
  Warning  Unhealthy  44s (x3 over 1m)  kubelet, minikube  Liveness probe failed: Get http://172.17.0.21:8080/ping: dial tcp 172.17.0.21:8080: connect: connection refused

为什么我的连接只会被 Pod 的 IP 拒绝?

编辑我没有运行任何自定义网络的东西,只是开箱即用的 minikube

【问题讨论】:

    标签: docker kubernetes minikube


    【解决方案1】:

    为什么我的连接只会被 Pod 的 IP 拒绝?

    因为您的程序显然只在本地主机上监听(又名127.0.0.1 又名lo0

    在不了解您的容器的更多信息的情况下,我们无法为您提供进一步的建议,但根据您的描述,这几乎肯定是问题所在。

    【讨论】:

    • 就是这样。谢谢您的意见。非常感谢!
    • 我很高兴听到它,我很高兴为您在 SO 上的体验做出了贡献。请将我的答案标记为已接受,以便其他人可以看到解决方案
    猜你喜欢
    • 2021-11-12
    • 1970-01-01
    • 2020-06-19
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    • 2020-04-22
    • 2022-11-22
    • 1970-01-01
    相关资源
    最近更新 更多