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

7,074 views
Skip to first unread message

Sambit Mishra

unread,
May 31, 2017, 4:42:10 PM5/31/17
to Kubernetes user discussion and Q&A
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 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 ? 

Guangya Liu

unread,
May 31, 2017, 7:29:53 PM5/31/17
to kubernet...@googlegroups.com
Does it works if using a full path for `ps`? such as `/your/pspath/ps -ef | grep my_process_name`

--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.

Rodrigo Campos

unread,
May 31, 2017, 7:38:43 PM5/31/17
to kubernet...@googlegroups.com
You should use an array, like ["command", ... ], IIRC the syntax correctly
--

Guangya Liu

unread,
May 31, 2017, 7:42:13 PM5/31/17
to kubernet...@googlegroups.com
Yes, should use array, here is an example:

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

I think that you can probably run the case https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/ here first and then update the template step by step to fit your case.

Rodrigo Campos

unread,
Jun 1, 2017, 3:41:33 PM6/1/17
to kubernet...@googlegroups.com
Did it worked? :)

(note that both formats, Guangya Liu used and I, are valid in yaml for arrays,
so both should be fine, choose the one you prefer).
> >> email to kubernetes-use...@googlegroups.com.
> >> To post to this group, send email to kubernet...@googlegroups.com.
> >> Visit this group at https://groups.google.com/group/kubernetes-users.
> >> For more options, visit https://groups.google.com/d/optout.
> >>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Kubernetes user discussion and Q&A" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to kubernetes-use...@googlegroups.com.
> > To post to this group, send email to kubernet...@googlegroups.com.
> > Visit this group at https://groups.google.com/group/kubernetes-users.
> > For more options, visit https://groups.google.com/d/optout.
> >
>
> --
> You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-use...@googlegroups.com.
> To post to this group, send email to kubernet...@googlegroups.com.

Matthias Rampke

unread,
Jun 1, 2017, 4:06:18 PM6/1/17
to kubernet...@googlegroups.com

Note that the probe command is executed directly, not in a shell, but you are using a pipe. try this:

command:
- sh
- -ec


- ps -ef | grep my_process_name

aside from that - don't run multiple processes in a container; use multiple containers in a pod instead. Make sure that when your process exits, the main command does; the best way is to ensure that everything is exec'd instead of running as subprocesses. Then, you don't need this probe as the container runtime will know that your process is no longer running and will restart it automatically.

/MR

Reply all
Reply to author
Forward
0 new messages