下面的livenessProbe(取自一个示例)正在良好地运行。
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
但是,我的 livenessProbe 不起作用(pod 不断重启)。 YAML 如下:
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness-test
name: liveness
spec:
containers:
- name: liveness
args:
- /bin/bash
- -c
- /home/my_home/run_myprogram.sh; sleep 20
image: liveness:v0.6
securityContext:
privileged: true
livenessProbe:
exec:
command:
- /home/my_home/check.sh
initialDelaySeconds: 10
periodSeconds: 5
以下是/home/my_home/check.sh的内容(用于在运行进程数为1或0时重新启动Pod),已经过预测试。
#!/bin/sh
if [ $(ps -ef | grep -v grep | grep my-program | wc -l) -lt 2 ]; then
exit 1
else
exit 0
fi