why both liveness is needed with readiness

2/18/2019

While doing health check for kubernetes pods, why liveness probe is needed even though we already maintain readiness probe ?

Readiness probe already keeps on checking if the application within pod is ready to serve requests or not, which means that the pod is live. But still, why liveness probe is needed ?

-- Ramesh
kubernetes
kubernetes-health-check

3 Answers

2/18/2019

The readiness probe checks that your application is ready to serve the requests or not and it will not add that particular pod to ready pod pull until it satisfy readiness checks. The main difference is that it doesnt restart the pod if a pod is not ready.

Liveness probe checks if the pod is not ready(not satisfying specific condition) it will restart the pod in a hope that this pod will recover and becomes ready.

-- Prafull Ladha
Source: StackOverflow

2/18/2019

The probes have different meaning with different results:

  • failing liveness probes -> restart container
  • failing readiness probes -> do not send traffic to that pod

You can not determine liveness from readiness and vice-versa. Just because pod cannot accept traffic right know, doesn't mean restart is needed, it can mean that it just needs time to finish some work.

If you are deploying e.g. php app, those two will probably be the same, but k8s is a generic system, that supports many types of workloads.


From: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/

The kubelet uses liveness probes to know when to restart a Container. For example, liveness probes could catch a deadlock, where an application is running, but unable to make progress. Restarting a Container in such a state can help to make the application more available despite bugs.

The kubelet uses readiness probes to know when a Container is ready to start accepting traffic. A Pod is considered ready when all of its Containers are ready. One use of this signal is to control which Pods are used as backends for Services. When a Pod is not ready, it is removed from Service load balancers.


Sidenote: Actually readiness should be a subset of liveness, that means readiness implies liveness (and failing liveness implies failing readiness). But that doesn't change the explanation above, because if you have only readiness, you can only imply when restart is NOT needed, which is the same as not having any probe for restarting at all. Also because of probes are defined separately there is no guarantee for k8s, that one is subset of the other

-- michalhosna
Source: StackOverflow

4/20/2020

Kubernetes allows you to define few things to make the app available.

1: Liveness probes for your Container.

2: Readiness probes for your Pod.

1- Liveness probes: They help keep your apps healthy by ensuring unhealthy containers are restarted automatically.

2: Readiness probes They help by invoking periodically and determines whether the specific Pod should receive client requests or not.


Operation of Readiness Probes

When a container is started, Kubernetes can be configured to wait for a configurable amount of time to pass before performing the first readiness check. After that, it invokes the probe periodically and acts based on the result of the readiness probe.

  • If a pod reports that it’s not ready, it’s removed from the service. Just think like- The effect is the same as when the pod doesn’t match the service’s label selector at all.
  • If the pod then becomes ready again, it’s re-added.

Important difference between liveness and readiness probes

1: Unlike liveness probes(i:e as mentioned above "If a pod reports that it’s not ready, it’s removed from the service"), if a container fails the readiness check, it won’t be killed or restarted.

2: Liveness probes keep pods healthy by killing off unhealthy containers and replacing them with new, healthy ones, whereas readiness probes make sure that only pods that are ready to serve requests receive them

I hope this helps you better.

-- Gupta
Source: StackOverflow