Many applications running for long periods of time eventually transition to broken states, and cannot recover except by being restarted. Kubernetes provides liveness probes to detect and remedy such situations.
apiVersion: batch/v1
kind: Job
metadata:
labels:
test: liveness
name: liveness-exec
spec:
ttlSecondsAfterFinished: 100
backoffLimit: 4
template:
spec:
restartPolicy: Never
containers:
- name: liveness
image: k8s.gcr.io/busybox
volumeMounts:
- name: tempdir
mountPath: "/tmp"
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
terminationMessagePolicy: FallbackToLogsOnError
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
volumes:
- name: tempdir
emptyDir: {}