Skip to content

Today I learned

Learn something new every day

Menu
  • Home
  • About
  • Hello World! and Why I Started This Blog
Menu
pod lifecycle

Ready, Alive, Go! – Health Checks in Kubernetes explained

Posted on 06/04/202205/04/2022 by Sagi Rosenthal

Today I learned about how Liveness and Readiness probes work in Kubernetes. Not everyone knows, but there are actually 3 available probes in Kubernetes: liveness, readiness, and startup. Each has its own reason and effect for success or failure. And, most important, have best practices for how and what to use.

Why

The importance of health checks in Kubernetes is important for two reasons. One- to make sure we manage to load a new pod successfully. Tow- in order to make sure our application runs smoothly, and auto-remediate some fatal cases. If you want to keep your application service at top-grade and make the deployment long-lasting. I REALLY recommend sticking to these best practices. Don’t try to workaround the probes to your case, adapt your case to the probes.

What

I believe this table should explain best the difference between the actions of the probe:

use-caseLivenessReadinessStartup
What happens after initial successNothingThe pod starts to receive external trafficLiveness and Readiness probes start to take action
What happens if the probe never succededPod will restartNothingPod will restart
What happens if the probe succeeded and later on it failsPod will restartThe pod will stop receiving new traffic Does not apply

To sum up, the recommended checks for each probe are:

  1. Liveness– to check up on dead-locks in your running app. most people actually get this probe wrong by checking if they can get a simple HTTP response from their app. This is not the correct way because usually HTTP servers run in a different thread and this does not assure that your program is not stuck somewhere else in your code.
  2. Readiness – to signal that your application is prepared to serve traffic. This means you manage to initiate all required dependencies including populating internal memory and successfully connected to external services such as DB or remote backend service. This is also the reason why you should report back when an external connection was broken.
  3. Startup – from Kubernetes’ official documentation: “Sometimes, you have to deal with legacy applications that might require an additional startup time on their first initialization. In such cases, it can be tricky to set up liveness probe parameters without compromising the fast response to deadlocks that motivated such a probe.“

How

As I mentioned, each probe covers a different aspect and has different results on success or failure. But they are all being checked from the Kubernetes side in the same way.
The execution of the check can be done by running a command in your container (which should not be available if you run from scratch) or using a network port (TCP, HTTP, or even gRPC from Kubernetes 1.23+).
In terms of timing, you can control the initial delay where the probe is not being checked, the regular checking period in seconds, and even the probe timeout.
And sometimes you want to tweak the success or failure criteria. You might don’t want that a single error will terminate your running container.

For further reading:
Container Probes: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes
Probes definitions on Kubernetes documentation: https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#Probe

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

CAPTCHA


Recent Posts

  • How to Sell Stuff Online
  • How to Make Your Kubernetes Dev Cycle Faster
  • How To Be A Valuable Team Member
  • Don’t Make, Go Generate It
  • Why You Should Monkey Patch Your Next Unit-Test

Archives

  • July 2023
  • April 2023
  • January 2023
  • November 2022
  • August 2022
  • July 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022

Categories

  • Go
  • Learning
  • Software Utilities
Join the updates channel
© 2026 Today I learned | Powered by Minimalist Blog WordPress Theme