Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why both liveness is needed with readiness

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 ?

like image 434
Ramesh Avatar asked Feb 18 '19 10:02

Ramesh


People also ask

Why do we need liveness and readiness probe?

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.

What is the difference between readiness probe and liveness probe?

Using a Readiness Probe, Kubernetes will wait until your application is fully started before it allows the service to send traffic to the new copy. Liveness Probes: Liveness Probes indicate whether your container is running. If the check fails your container will be restarted.

What is use of liveness and readiness in Kubernetes?

readinessprobe attribute of the pod configuration. Liveness probes determine whether or not an application running in a container is in a healthy state. If the liveness probe detects an unhealthy state, then Kubernetes kills the container and tries to redeploy it. The liveness probe is configured in the spec.


1 Answers

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

like image 145
michalhosna Avatar answered Oct 03 '22 20:10

michalhosna