Sobes.tech
Middle — Middle+

What is the purpose of livenessProbe in Kubernetes and why is it used?

sobes.tech AI

Answer from AI

LivenessProbe in Kubernetes is used to check if a container is alive and functioning correctly. If the livenessProbe fails, Kubernetes considers the container to be 'stuck' or in an unhealthy state and restarts it. This helps automatically recover applications that have stopped responding, ensuring high availability.

Example of using livenessProbe in a Pod manifest:

livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  initialDelaySeconds: 15
  periodSeconds: 20

Here, Kubernetes will make HTTP requests to /healthz on port 8080, starting 15 seconds after launch, every 20 seconds, to check the container's status.