kubernetes 健康检查查找字符串

kubernetes health check look for string

我有一个带有 ping 端点 (returns pong) 的容器,我想探测 ping 端点并查看是否能返回 pong。如果只是为了检查 200 ,我可以像这样在我的 pod 中添加一个活跃度检查 ->

livenessProbe:
  initialDelaySeconds: 2
  periodSeconds: 5
  httpGet:
    path: /ping
    port: 9876 

如何修改它以检查我是否收到 pong 响应?

由于 HTTP 探测仅检查响应的状态代码,因此您需要使用 exec 探测 运行 容器上的命令。像这样的东西,需要在容器上安装 curl

livenessProbe:
  initialDelaySeconds: 2
  periodSeconds: 5
  exec:
    command:
    - sh
    - -c
    - curl -s http://localhost:9876/ping | grep pong

http获取livenessProbe和readinessProbe只关心http响应码

Any code greater than or equal to 200 and less than 400 indicates success. Any other code indicates failure.

最好更改您的 pong 消息以在响应中设置适当的 http 状态代码。