Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add kubernetes liveness probe to check if a process is alive

Tags:

kubernetes

I have a process running inside an Ubuntu container and would like to redeploy the container if the process gets killed. I added the following liveness probe in container spec

  livenessProbe:
    exec:
     command:
     - ps -ef | grep my_process_name
    initialDelaySeconds: 120
    periodSeconds: 30

However this doesnt work. When I do a kubectl describe pods <pod_id> I get the following event.

  1h    6m      20      {kubelet k8s-agent-71e8d996-0}        spec.containers{my_process_name}       Warning Unhealthy       Liveness       probe failed: rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"exec: \\\"ps -ef | grep my_process_name\\\": executable file not found in $PATH\"\n"

And it keeps redeploying the container. If I bash into the container and do a 'ps -ef' it works but this doesnt Whats a good way to use the liveness probe to check if a process is running or not ? Thanks.

like image 230
user3499908 Avatar asked May 31 '17 20:05

user3499908


1 Answers

Make sure ps is installed. If it does not run: apt-get update && apt-get install procps

For the ease of copy-pasting OP's comment under the question :-).

Below, worker.py is the process that needs to be checked:

livenessProbe:
  exec:
    command:
    - /bin/bash
    - -c
    - ps -ef | grep worker.py | grep -v grep
  initialDelaySeconds: 10
  periodSeconds: 10
like image 175
arun Avatar answered Oct 13 '22 12:10

arun