My pods sometimes appear that restarted automatically, but I don't have a liveness yet. I read that it can be the lifecycle of the pod that when you don't specify a RestartPolicy, by default is Always and when a Container crash, it restart automatically. But, I got confused because I thought that the liveness should do that. And as the lifecycle already do it, for what should I use the liveness probe? And as it is two different things, what is the difference between then?
What's the difference between Pod lifecycle and liveness?
155 views Asked by Arthur Ávila At
2
If your app in the container crashes on its own, then k8s will restart it automatically. If you have a liveness probe, your POD may be restarted if the liveness probe fails. So in your situation, since you do not have a liveness probe, it is probably due to your app crashing.
Let's say your app is able to get in a state where it no longer executes requests, but it is not crashed (aka it is still up and running). This may happen if for example you have a deadlock in the code somewhere. In this case a liveness probe might be useful. The probe could test whether or not the app is in this deadlocked state. If so, the liveness probe would fail, and the POD restarted.
The difference is whether or not your app can go into a state where it is effectively down (not able to properly execute requests) while still remaining technically up (the PID in the container is still running). If your app can go into such a state, then I would say that a liveness probe is a good idea. It might also be a good idea if you do not know the answer to this question. If no harm can be done by having a liveness probe, then it might be a good idea. You'll just want to avoid restarting a perfectly fine POD if there is no problem.