首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Kubernetes中的startupProbe中正确执行命令?

如何在Kubernetes中的startupProbe中正确执行命令?
EN

Stack Overflow用户
提问于 2022-02-23 17:23:37
回答 1查看 518关注 0票数 0

我正在尝试使用这个启动探针

代码语言:javascript
复制
          startupProbe:
            exec:
              command:
                - >-
                  test $(java -cp /the/path/to/the/app.jar app.Controller port=4990 cmd="v" | grep -E 'r5|v5' | wc -l) -eq 2 && echo $? || echo $?
            initialDelaySeconds: 5 #How many seconds to wait after the container has started
            timeoutSeconds: 1 #Timeout of the probe
            successThreshold: 1 #Threshold needed to mark the container healthy
            periodSeconds   : 10 #Wait time between probe executions
            failureThreshold: 110 #Threshold needed to mark the container unhealthy.

这是一个java应用程序,需要很长时间(大约15分钟)来加载一些组件。这是一个遗留的应用程序,我对此无能为力。

我正在修改响应,尝试得到两行结果,然后返回0或1作为退出代码,由探针决定。

但我明白他的错误

代码语言:javascript
复制
Startup probe errored: rpc error: code = Unknown desc = failed to exec in container: failed to start exec "8ad860ffc7a87e95fb65e37dc14945c04fa205f9a524c7f7f08f9d6ef7d75": OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "test $(java -cp /the/path/to/the/app.jar app.Controller port=4990 cmd=\"v\" | grep -E 'r5|v5' | wc -l) -eq 2 && echo $? || echo $?": stat test $(java -cp /the/path/to/the/app.jar app.Controller port=4990 cmd="v" | grep -E 'r5|v5' | wc -l) -eq 2 && echo $? || echo $?: no such file or directory: unknown

如果我不使用&& echo $? || echo $?部件,探针会引发错误,即退出代码是2而不是1

怎么回事??

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-24 03:13:13

您需要启动一个shell来运行脚本:

代码语言:javascript
复制
startupProbe:
  exec:
    command:
    - sh
    - -c
    - >-
      ...
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71241490

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档