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

1/23/2021

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

  • startupProbe
  • readinessProbe
  • livenessProbe

There are some questions (https://stackoverflow.com/questions/55423405/k8s-livenessprobe-vs-readinessprobe, https://stackoverflow.com/questions/59850959/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?
-- Matthias M
kubernetes

2 Answers

1/23/2021

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

-- Matthias M
Source: StackOverflow

12/22/2021

The difference between livenessProbe, readinessProbe, and startupProbe

livenessProbe:

 livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 3
      periodSeconds: 3
  • It is used to indicate if the container has started and is alive or not i.e. proof of being avaliable.
  • In the given example, if the request fails, it will restart the container.
  • If not provided the default state is Success.

readinessProbe:

 readinessProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 3
      periodSeconds: 3
  • It is used to indicate if the container is ready to serve traffic or not i.e.proof of being ready to use.
  • It checks dependencies like database connections or other services your container is depending on to fulfill its work.
  • In the given example, until the request returns Success, it won't serve any traffic(by removing the Pod’s IP address from the endpoints of all Services that match the Pod).
  • Kubernetes relies on the readiness probes during rolling updates, it keeps the old container up and running until the new service declares that it is ready to take traffic.
  • If not provided the default state is Success.

startupProbe:

 startupProbe:
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 3
      periodSeconds: 3
  • It is used to indicate if the application inside the Container has started.
  • If a startup probe is provided, all other probes are disabled.
  • In the given example, if the request fails, it will restart the container.
  • Once the startup probe has succeeded once, the liveness probe takes over to provide a fast response to container deadlocks.
  • If not provided the default state is Success.

Check K8S documenation for more.

-- Mostafa Wael
Source: StackOverflow