Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need 3 different kind of probes in kubernetes: startupProbe, readinessProbe, livenessProbe

Tags:

kubernetes

Why do I need 3 different kind of probes in kubernetes:

  • startupProbe
  • readinessProbe
  • livenessProbe

There are some questions (k8s - livenessProbe vs readinessProbe, Setting up a readiness, liveness or startup probe) and articles about this topic. But this is not so clear:

  • Why do I need 3 different kind of probes?
  • What are the use cases?
  • What are the best practises?
like image 597
Matthias M Avatar asked Jan 23 '21 10:01

Matthias M


Video Answer


1 Answers

These 3 kind of probes have 3 different use cases. That's why we need 3 kind of probes.

Liveness Probe

If the Liveness Probe fails, the pod will be restarted (read more about failureThreshold).

Use case: Restart pod, if the pod is dead.

Best practices: Only include basic checks in the liveness probe. Never include checks on connections to other services (e.g. database). The check shouldn't take too long to complete. Always specify a light Liveness Probe to make sure that the pod will be restarted, if the pod is really dead.

Startup Probe

Startup Probes check, when the pod is available after startup.

Use case: Send traffic to the pod, as soon as the pod is available after startup. Startup probes might take longer to complete, because they are only called on initializing. They might call a warmup task (but also consider init containers for initialization).

Best practices: Specify a Startup Probe, if the pod takes a long time to start. The Startup and Liveness Probe can use the same endpoint, but the Startup Probe will have a less strict failure threshhold which prevents a failure on startup (s. Kubernetes in Action).

Readiness Probe

In contrast to Startup Probes Readiness Probes check, if the pod is available during the complete lifecycle. In contrast to Liveness Probes only the traffic to the pod is stopped, if the Readiness probe fails, but there will be no restart.

Use case: Stop sending traffic to the pod, if the pod can not temporarily serve because a connection to another service (e.g. database) fails and the pod will recover later.

Best practices: Include all necessary checks including connections to other services. Nevertheless the check shouldn't take too long to complete. Always specify a Readiness Probe to make sure that the pod only gets traffic, if the pod can properly handle incoming requests.

Documentation

  • This article explains very well the differences between the 3 kind of probes.
  • The Official kubernetes documentation gives a good overview about all configuration options.
  • Best practises for probes.
  • The book Kubernetes in Action gives most detailed insights about the best practises.
like image 88
Matthias M Avatar answered Sep 26 '22 07:09

Matthias M