Kubernetes:如何在就绪探测命令中传递管道字符 [英] Kubernetes: How to pass pipe character in readiness probe command

查看:25
本文介绍了Kubernetes:如何在就绪探测命令中传递管道字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在就绪探测命令中传递管道字符|时遇到问题。

我想要一个探测命令:

curl --silent http://localhost:8080/actuator/health | grep --quiet -e '^{"status":"UP".*}$'

以下是我定义探测器的方式:

# kubectl get pod my_pod -o yaml

readinessProbe:
  exec:
    command:
    - curl
    - --silent
    - http://localhost:8080/actuator/health
    - '|'
    - grep
    - --quiet
    - -e
    - '''^{"status":"UP".*}$'''

就绪探测失败,并显示消息:

就绪性探测失败:curl:选项--Quiet:是未知的curl:有关详细信息,请尝试‘curl--help’或‘curl--Manual’

在没有管道字符的情况下执行命令时可以重现错误|

curl --silent http://localhost:8080/actuator/health grep --quiet -e '^{"status":"UP".*}$'

由于某种原因,Kubernetes无法解释管道。

您能帮我在部署中通过管道吗?

推荐答案

kubernetes本身并不运行Shell来处理命令;它只是直接运行这些命令。shell中最接近的等价物是

curl '--silent' 'http://...' '|' 'grep' ...

也就是说,这里的|没有拆分两个单独的命令,因为这是shell语法;如果没有shell,它将成为curl的另一个参数,它后面的所有单词也是如此。

您需要自己提供外壳包装:

readinessProbe:
  exec:
    command:
      - sh
      - -c
      - curl --silent http://localhost:8080/actuator/health | grep --quiet -e '^{"status":"UP".*}$'

您可以使用替代的YAML语法来使其更具可读性。(>表示将后面的行折成一个字符串;-表示去掉前导空格和尾随空格。

readinessProbe:
  exec:
    command:
      - sh
      - -c
      - >-
         curl --silent http://localhost:8080/actuator/health |
         grep --quiet -e '^{"status":"UP".*}$'

这篇关于Kubernetes:如何在就绪探测命令中传递管道字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆