Pods and Container are running but application is might dead because of some reason. To Detect and resolve problem with application we need to use Liveness (Healthcheck)
Liveness probe checks the container health as we tell it do, and if for some reason the liveness probe fails, it restarts the container.
Liveness Probe source Thanks to (https://wideops.com/)
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-exec
spec:
containers:
- name: liveness
image: k8s.gcr.io/busybox
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 3
periodSeconds: 5
We are creating a container with name liveness, and as the container initialise we use the following command:
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
This commands tell the liveness probe to open file at path /tmp/healthy, and if it can’t the liveness probe will fail and container will restart.
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 3
periodSeconds: 5