如何定义一个活体检测命令

19

下面的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
1个回答

29

这个问题与Golang命令API有关。 我将livenessProbe更改如下:

livenessProbe:
  exec:
    command:
    - /bin/sh
    - -c
    - /home/test/check.sh

以上代码是有效的,但如果我们在旁路容器中使用相同的代码,则会出现以下错误提示: 存活探针失败:OCI运行时执行失败:执行失败:container_linux.go:345:启动容器进程导致“exec:“/bin/sh /opt/test/check.sh”:stat /bin/sh /opt/test/check.sh:没有那个文件或目录”:未知。请问您有什么建议? - Mercury
1
您的辅助容器未安装/bin/sh。 - binglong li

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接