Kubernetes probes
This article has the objective of demystifying Kubernetes probes.
Introduction
There are 3 probe types that k8s (Kubernetes) uses to check the conditions of your application: startup, readiness and liveness. They are super important to use, even if your application is just a small one, since you can increase availability with them and make your application, in general, more stable.
What are those probes?
Here's a short description of each of them:
- startupProbe: This one is used to tell k8s whether your application has started properly.
- readinessProbe: This one tells k8s whether the application is ready to receive requests.
- livenessProbe: This one tells k8s whether the application is actually alive.
Startup probe
startupProbe is useful if your app needs some time to startup - e.g. seconds or even minutes, depending on what it does. Whenever a startupProbe is running and success hasn't yet been achieved, no other probes run, since k8s needs the app to tell that it has started properly before k8s even tries to do anything with it.
For some time, I thought that was the purpose of readinessProbe, but I was wrong. Why don't we explain that's the purpose of the readinessProbe then, shall we?
Readiness probe
readinessProbe has the purpose of telling k8s that the application is ready to receive requests; For example, if you have a Deployment and a Service related to it, but the readinessProbe fails on a certain pod, then the Service related that pod won't direct requests to it, but instead to other pods in the ReplicaSet - supposing you have more than 1 pod.
This is useful if you need to take the pod out of the replicas in order to do some lengthy process with it, maybe a database migration or a data report or something like that (of course, it might be a bad idea to do that with an app that has the purpose of receiving requests from a Service, but you get the point).
readinessProbe and livenessProbe are independent of each other, and they don't wait for each other to finish when they start.
Liveness probe
livenessProbe is probably the most used probe here. It's the one that tells whether your application is fine, during its entire lifetime. It's the one you should always be using if you have an application that's supposed to be running indefinitely, so that k8s can check its health and, if needed, terminate it so that a fresh new pod can be started for the app.
readinessProbe and livenessProbe are independent of each other, and they don't wait for each other to finish when they start.
Conclusion
Understanding these probes is very important as they are very helpful to improve the reliability of your applications, no matter what they do. They might be ETL jobs, web applications, it doesn't matter; If you're running it in k8s, then it's worth using probes in general.
You can find more information about probes here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/