How to define a liveness command

jazzsir picture jazzsir · Aug 12, 2017 · Viewed 9.5k times · Source

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

Answer

jazzsir picture jazzsir · Aug 13, 2017

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

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