Readiness-在 Pod 启动时探测另一个服务

Readiness-Probe another Service on boot-up of Pod

在我的 Kubernetes 设置中,我有 2 个服务 - A 和 B。
服务 B 依赖于服务 A 的完全启动。 我现在想在服务 B 的 Pods 中设置一个 TCP Readiness-Probe,以便他们测试服务 A 的任何 Pod 是否完全运行。

服务 B 中部署的 ReadinessProbe 部分如下所示:

readinessProbe:
  tcpSocket:
    host: serviceA.mynamespace.svc.cluster.local
    port: 1101 # same port of Service A Readiness Check

我可以应用这些更改,但就绪探测失败并显示:

Readiness probe failed: dial tcp: lookup serviceB.mynamespace.svc.cluster.local: no such host

我在其他地方使用相同的主机名(例如,我将其作为 ENV 传递给容器)并且它可以正常工作并得到解决。

有没有人想过让其他服务做好准备或在服务之间进行其他类型的依赖性检查? 谢谢:)

由于 Readiness 和 Liveness probes are fully managed by kubelet node agent and kubelet inherits DNS discovery service from the particular Node configuration, you are not able to resolve K8s internal nameserver DNS 记录:

For a probe, the kubelet makes the probe connection at the node, not in the pod, which means that you can not use a service name in the host parameter since the kubelet is unable to resolve it.

您可以考虑当您的源 Pod A 通过传播 hostNetwork: true 参数使用节点 IP 地址时的场景,因此 kubelet 可以到达并成功进行就绪探测在 Pod B 内,如官方 k8s documentation:

中所述
tcpSocket:
  host: Node Hostname or IP address where Pod A residing
  port: 1101

不过,我找到了 Stack , where you can get more efficient solution how to achieve the same result through Init Containers

除了Nick_Kh的答案之外,另一种解决方法是使用probe by command,它在容器中执行。

To perform a probe, the kubelet executes the command cat /tmp/healthy in the target container. If the command succeeds, it returns 0, and the kubelet considers the container to be alive and healthy.

一个例子:

readinessProbe:
  exec:
    command:
     - sh
     - -c
     - wget -T2 -O- http://service