【问题标题】:How to configure a livenessProbe in Kubernetes based Eclipse Microprofile如何在基于 Kubernetes 的 Eclipse Microprofile 中配置 livenessProbe
【发布时间】:2020-04-11 13:27:57
【问题描述】:

我正在运行基于 Eclipse Microprofile 的休息服务。我的服务提供健康检查。这种健康检查(提供大量信息)的结果如下所示:

http://localhost:9990/health
HTTP=OK

{
  "status":"UP",
  "checks":[
    {"name":"imixs-workflow",
     "status":"UP",
     "data":
     {
     "engine.version":"5.1.11-SNAPSHOT",
     "model.groups":30,
     "model.versions":20
     }
    }
  ]
}

如果名为“imixs-workflow”的检查显示“状态”“UP”,则服务是健康的。

我已经尝试使用这样的 livenessprobe 进行配置:

livenessProbe:
  exec:
    command: ["sh", "-c", "curl -s http://localhost:9990/health| grep -q imixs-workflow"]
  initialDelaySeconds: 60

但这不起作用。

我应该如何配置这样一个 livenessprobe 来获取 http 结果中特定 json 字段的状态?

【问题讨论】:

    标签: kubernetes microprofile


    【解决方案1】:

    您的 liveness probe 命令应该返回不同于 0 的状态以指示不健康的容器状况。请参阅Configure Liveness, Readiness and Startup Probes

    如果可能的话,我还建议使用名为jq 的工具——命令行 JSON 处理器,以获得更好的可维护性和可读性。

    有了它,你的探针应该看起来像这样:

    livenessProbe:
      exec:
        command: ["sh", "-c", "curl -s http://localhost:9990/health | jq -e '.checks[] | select(.name == "imixs-workflow") | .status == "UP"']
      initialDelaySeconds: 60
    

    这里-e 标志将退出状态设置为 1,如果最后一个输出值为假。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 2011-03-28
      • 2017-11-06
      • 2019-12-08
      • 2021-12-03
      • 2023-03-05
      • 2023-01-18
      相关资源
      最近更新 更多