15

下面的 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
4

1 回答 1

23

这个问题与Golang Command API有关。我改变了 livenessProbe 如下

livenessProbe:
  exec:
    command:
    - /bin/sh
    - -c
    - /home/test/check.sh
于 2017-08-13T09:40:51.387 回答