【问题标题】:Kubernetes - How to read response body in livenessProbe of a container?Kubernetes - 如何在容器的 livenessProbe 中读取响应体?
【发布时间】:2021-12-03 03:08:52
【问题描述】:

以下是 livenessProbe 的当前配置:

   livenessProbe:
        httpGet:
          path: /heartbeat
          port: 8000
        initialDelaySeconds: 2
        timeoutSeconds: 2
        periodSeconds: 8
        failureThreshold: 2

但 URL .well-known/heartbeat 的响应正文显示 status: "DOWN" 并且 http 返回状态为 200

因此,由于 http 响应状态为 200,Kubelet 不会重启容器


如何确保 Kubelet 读取响应正文而不是 http 返回状态?使用livenessProbe配置

【问题讨论】:

    标签: kubernetes kubelet livenessprobe


    【解决方案1】:

    如何确保 Kubelet 读取响应正文而不是 http 返回状态?使用 livenessProbe 配置

    这不符合 Kubernetes 提供的“合约”。您可能需要实现一个自定义端点,该端点遵循 HTTP 活性探测合同,如下所示。

    来自Define a HTTP liveness probe

    如果处理程序返回失败代码,kubelet 会杀死容器并重新启动它。

    任何大于或等于 200 且小于 400 的代码都表示成功。任何其他代码都表示失败。

    【讨论】:

      【解决方案2】:

      您可以使用 shell 命令解释探针中的主体,例如:

      livenessProbe:
        exec:
          command:
          - sh
          - -c
          - curl -s localhost | grep 'status: "UP"'
      

      grep 如果 status: "DOWN" 返回非零值,这将指示 readinessProbe 失败。你当然可以根据自己的实际响应体调整脚本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-11-06
        • 2012-11-30
        • 2016-03-25
        • 2013-01-16
        • 1970-01-01
        • 1970-01-01
        • 2020-10-12
        相关资源
        最近更新 更多