如何否定要在 Kubernetes
中使用的退出代码状态livenessProbe
?
我将使用 grep
命令,我想在下面做一个检查。
grep
没有命中grep
成功了由于通常情况下,如果有命中,grep 将返回 0,我可以否定这个,如下所示?
!$(cat filet.txt | grep keyword)
最佳答案
是的,你可以试试
例子 :
livenessProbe:
exec:
command:
- /bin/bash
- -c
- cat filet.txt | grep keyword
initialDelaySeconds: 10
periodSeconds: 10
如果有帮助,您应该结帐-v, --invert-match
Invert the sense of matching, to select non-matching lines.
你也可以试试-c
echo 'Test' | grep -c T
1 echo 'Test' | grep -c N
0 外壳脚本
#!/bin/sh
if [ $(echo 'Test' | grep -c T) ]; then
exit 1
else
exit 0
fi
最简单的方法是编写 shell 脚本并根据需要管理事件的退出代码 0 或 1,并且基于该事件将重新启动 pod。livenessProbe:
exec:
command:
- /bin/sh
- -c
- /home/test/health.sh
关于linux - 如何否定要在 Kubernetes livenessProbe 中使用的退出代码状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69293621/