19

A livenessProbe (extracted from an example) below is working well.

livenessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy

But, my livenessProbe is not working.(pod is continually restarted). YAML is below

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 (to restart the pod when the number of running processes is 1 or 0) is below, which is pre-tested.

#!/bin/sh
if [ $(ps -ef | grep -v grep | grep my-program | wc -l) -lt 2 ]; then
  exit 1
else
  exit 0
fi
jazzsir
  • 609
  • 2
  • 7
  • 14

1 Answers1

29

This problem is related to Golang Command API. I changed the livenessProbe as below

livenessProbe:
  exec:
    command:
    - /bin/sh
    - -c
    - /home/test/check.sh
jazzsir
  • 609
  • 2
  • 7
  • 14
  • The above works, however if we use the same in sidecar container it states: Liveness probe failed: OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "exec: \"/bin/sh /opt/test/check.sh\": stat /bin/sh /opt/test/check.sh: no such file or directory": unknown. Can you suggest what could go wrong ? – Mercury Nov 04 '19 at 10:59
  • 1
    Your sidecar container does not have /bin/sh installed. – binglong li Jan 10 '22 at 04:36