Member-only story
Kubernetes Liveness, Readiness Probe Explained

In Kubernetes, other than the restartPolicy
which defaults to restart the pod when a pod fails. There are Liveness and Readiness probes to control and manage the lifecycle of a pod.
Liveness Probe
A liveness Probe is used by the kubelet
to know when to restart the container inside a pod. This probe can help restart the container when the application is not responding to the request or the response time is too long.
There are 3 main ways to check the container’s health using a liveness probe.
- Liveness command
apiVersion: v1
kind: Pod
metadata:
name: webserver
spec:
containers:
- name: nginx
image: nginx:latest
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 3
periodSeconds: 30
We are creating a nginx
container inside the pod webserver
. The container has a livenessProbe
attached to it.
exec:
command:
- cat
- /tmp/healthy
If the command under exec
fails the kubelet will restart the container. In this case, if there is no file at /tmp/healthy
the container will restart.
initialDelaySeconds: 3
The value initialDelaySeconds
tells the kubelet to wait 3 seconds before performing the first probe. This is used to delay the probe when the container/application is starting up. Default is 0
periodSeconds: 30
The value periodSeconds
is the time between each probe. Default is 10
2. Liveness HTTP request
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 30
Replace the exec
under livenessProbe
with httpGet
.
The kubelet will send a GET
request to the /healthz
endpoint on port 8080
of the container. If the handler returns a success code, the kubelet considers the container to be healthy. If the handler returns a failure code the kubelet
will restart the container