Mic*_*ksa 3 openshift 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\".*}$'''
Run Code Online (Sandbox Code Playgroud)
就绪探测失败并显示以下消息:
就绪探测失败:curl:选项 --quiet:未知 curl:尝试“curl --help”或“curl --manual”以获取更多信息
在没有管道字符的情况下执行命令时可以重现错误|:
curl --silent http://localhost:8080/actuator/health grep --quiet -e '^{\"status\"\:\"UP\".*}$'
出于某种原因,Kubernetes 不会解释管道。
你能帮我在部署中传递管道吗?
Dav*_*aze 11
Kubernetes 不运行 shell 来自行处理命令;它只是直接运行它们。壳中最接近的等价物是
curl '--silent' 'http://...' '|' 'grep' ...
Run Code Online (Sandbox Code Playgroud)
也就是说,|这里没有拆分两个单独的命令,因为这是 shell 语法;如果没有外壳,它将成为 的另一个参数curl,就像它后面的所有单词一样。
您需要自己提供 shell 包装器:
readinessProbe:
exec:
command:
- sh
- -c
- curl --silent http://localhost:8080/actuator/health | grep --quiet -e '^{\"status\"\:\"UP\".*}$'
Run Code Online (Sandbox Code Playgroud)
您可以使用替代的 YAML 语法使其更具可读性。(>表示将以下行折叠成单个字符串;-表示去除前导和尾随空格。
readinessProbe:
exec:
command:
- sh
- -c
- >-
curl --silent http://localhost:8080/actuator/health |
grep --quiet -e '^{\"status\"\:\"UP\".*}$'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2807 次 |
| 最近记录: |