<p>A livenessProbe (extracted from <a href="https://raw.githubusercontent.com/kubernetes/kubernetes.github.io/master/docs/tasks/configure-pod-container/exec-liveness.yaml" rel="noreferrer">an example</a>) below is working well.</p>

<pre><code>livenessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy
</code></pre>

<p>But, my livenessProbe is not working.(pod is continually restarted).
YAML is below</p>

<pre><code>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
</code></pre>

<p>/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.</p>

<pre><code>#!/bin/sh
if [ $(ps -ef | grep -v grep | grep my-program | wc -l) -lt 2 ]; then
  exit 1
else
  exit 0
fi
</code></pre>

<p>This problem is related to <a href="https://golang.org/pkg/os/exec/#Command" rel="noreferrer">Golang Command API</a>.
I changed the livenessProbe as below</p>

<pre><code>livenessProbe:
  exec:
    command:
    - /bin/sh
    - -c
    - /home/test/check.sh
</code></pre>
