apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: test-liveness-exec
spec:
containers:
- name: liveness
image: busybox
args:
- /bin/sh
- -c
- touch /tmp/healthy; sleep 60; rm -rf /tmp/healthy; sleep 600
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
$ kubectl create -f test-liveness-exec.yaml
[root@dock01 ~]# kubectl exec -it test-liveness-exec -- /bin/sh
/ # cat /tmp/healthy
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 2m12s default-scheduler Successfully assigned default/test-liveness-exec to dock03
Normal Pulling 2m12s kubelet Pulling image "busybox"
Normal Pulled 2m7s kubelet Successfully pulled image "busybox" in 4.33586862s
Normal Created 2m7s kubelet Created container liveness
Normal Started 2m7s kubelet Started container liveness
Warning Unhealthy 4s kubelet Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory
/tmp # cat healthy
cat: can't open 'healthy': No such file or directory
[root@dock01 ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
labels-downwardapi-volume 1/1 Running 0 21h
nginx-deployment-20210106-5db4dd44c-657sx 1/1 Running 0 6d1h
nginx-deployment-20210106-5db4dd44c-bww7j 1/1 Running 0 6d1h
nginx-deployment-20210106-5db4dd44c-n9tvj 1/1 Running 0 6d1h
nginx-deployment-20210118-794fff54d4-dl2p8 1/1 Running 0 6d1h
nginx-deployment-20210118-794fff54d4-zgvt5 1/1 Running 0 6d1h
nginx-deployment-74cc47d99b-5ctwv 1/1 Running 0 6d1h
nginx-deployment-74cc47d99b-8c9lb 1/1 Running 0 6d1h
nginx-deployment-74cc47d99b-c86pc 1/1 Running 0 6d1h
nginx-deployment-74cc47d99b-gk9j9 1/1 Running 0 6d1h
nginx-deployment-74cc47d99b-v9vt7 1/1 Running 0 6d1h
test-downwardapi-volume 1/1 Running 1 4d3h
test-liveness-exec 1/1 Running 1 4m29s
test-projected-volume 1/1 Running 0 22h
tlcb-downwardapi-volume 1/1 Running 1 4d2h
web-0 1/1 Running 0 5d9h
web-1 1/1 Running 1 5d9h
test-liveness-exec 1/1 Running 1 4m29s