Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

k8s - livenessProbe vs readinessProbe

Tags:

kubernetes

Consider a pod which has a healthcheck setup via a http endpoint /health at port 80 and it takes almost 60 seconds to be actually ready & serve the traffic.

readinessProbe:   httpGet:     path: /health     port: 80   initialDelaySeconds: 60 livenessProbe:   httpGet:     path: /health     port: 80 

Questions:

  • Is my above config correct for the given requirement?
  • Does liveness probe start working only after the pod becomes ready ? In other words, I assume readiness probe job is complete once the POD is ready. After that livenessProbe takes care of health check. In this case, I can ignore the initialDelaySeconds for livenessProbe. If they are independent, what is the point of doing livenessProbe check when the pod itself is not ready! ?
  • Check this documentation. What do they mean by

If you want your Container to be able to take itself down for maintenance, you can specify a readiness probe that checks an endpoint specific to readiness that is different from the liveness probe.

I was assuming, the running pod will take itself down only if the livenessProbe fails. not the readinessProbe. The doc says other way.

Clarify!

like image 850
KitKarson Avatar asked Mar 29 '19 18:03

KitKarson


People also ask

What is the difference between livenessProbe and readinessProbe?

The only difference is that you use the readinessProbe field instead of the livenessProbe field. Configuration for HTTP and TCP readiness probes also remains identical to liveness probes. Readiness and liveness probes can be used in parallel for the same container.

What is liveness and readiness in Kubernetes?

Both liveness & readiness probes are used to control the health of an application. Failing liveness probe will restart the container, whereas failing readiness probe will stop our application from serving traffic.

What is livenessProbe in Kubernetes?

livenessProbe: Indicates whether the Container is running. If the liveness probe fails, the kubelet kills the Container, and the Container is subjected to its restart policy. If a Container does not provide a liveness probe, the default state is Success. readinessProbe.

How does readiness probe work in Kubernetes?

Readiness probes: This probe will tell you when your app is ready to serve traffic. Kubernetes will ensure the readiness probe passes before allowing a service to send traffic to the pod. If the readiness probe fails, Kubernetes will not send the traffic to the pod until it passes.


2 Answers

The liveness probes are to check if the container is started and alive. If this isn’t the case, kubernetes will eventually restart the container.

The readiness probes in turn also check dependencies like database connections or other services your container is depending on to fulfill it’s work. As a developer you have to invest here more time into the implementation than just for the liveness probes. You have to expose an endpoint which is also checking the mentioned dependencies when queried.

Your current configuration uses a health endpoint which are usually used by liveness probes. It probably doesn’t check if your services is really ready to take traffic.

Kubernetes relies on the readiness probes. During a rolling update, it will keep the old container up and running until the new service declares that it is ready to take traffic. Therefore the readiness probes have to be implemented correctly.

like image 92
Randy Avatar answered Oct 13 '22 03:10

Randy


I'm starting from the second problem to answer. The second question is:

Does liveness probe start working only after the pod becomes ready? In other words, I assume readiness probe job is complete once the POD is ready. After that livenessProbe takes care of health check.

Our initial understanding is that liveness probe will start to check after readiness probe was succeeded but it turn out not to be like that. It has opened an issue for this challenge.Yon can look up to here. Then It was solved this problem by adding startup probes.

To sum up:

  • livenessProbe

livenessProbe: Indicates whether the Container is running. If the liveness probe fails, the kubelet kills the Container, and the Container is subjected to its restart policy. If a Container does not provide a liveness probe, the default state is Success.

  • readinessProbe

readinessProbe: Indicates whether the Container is ready to service requests. If the readiness probe fails, the endpoints controller removes the Pod’s IP address from the endpoints of all Services that match the Pod. The default state of readiness before the initial delay is Failure. If a Container does not provide a readiness probe, the default state is Success.

  • startupProbe

startupProbe: Indicates whether the application within the Container is started. All other probes are disabled if a startup probe is provided, until it succeeds. If the startup probe fails, the kubelet kills the Container, and the Container is subjected to its restart policy. If a Container does not provide a startup probe, the default state is Success

look up here.

like image 38
fgul Avatar answered Oct 13 '22 01:10

fgul