root@master1:~/k8s-oc-yaml/application# kubectl create -f pod-liveness-exec.yaml
pod "liveness-exec" created
在30秒内,查看Pod的event:
kubectl describe pod liveness-exec
结果显示没有失败的liveness probe:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 1m default-scheduler Successfully assigned liveness-exec to node1
Normal SuccessfulMountVolume 1m kubelet, node1 MountVolume.SetUp succeeded for volume "default-token-8lv8j"
Normal Pulling 1m kubelet, node1 pulling image "registry.cn-hangzhou.aliyuncs.com/misa/busybox:1.28"
Normal Pulled 18s kubelet, node1 Successfully pulled image "registry.cn-hangzhou.aliyuncs.com/misa/busybox:1.28"
Normal Created 18s kubelet, node1 Created container
Normal Started 18s kubelet, node1 Started container
启动35秒后,再次查看pod的event:
kubectl describe pod liveness-exec
在最下面有一条信息显示liveness probe失败,容器被删掉并重新创建。
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 11m default-scheduler Successfully assigned liveness-exec to node1
Normal SuccessfulMountVolume 11m kubelet, node1 MountVolume.SetUp succeeded for volume "default-token-8lv8j"
Normal Pulling 11m kubelet, node1 pulling image "registry.cn-hangzhou.aliyuncs.com/misa/busybox:1.28"
Normal Pulled 10m kubelet, node1 Successfully pulled image "registry.cn-hangzhou.aliyuncs.com/misa/busybox:1.28"
Normal Started 8m (x3 over 10m) kubelet, node1 Started container
Normal Created 6m (x4 over 10m) kubelet, node1 Created container
Normal Killing 6m (x3 over 9m) kubelet, node1 Killing container with id docker://liveness:Container failed liveness probe.. Container will be killed and recreated.
Normal Pulled 6m (x3 over 9m) kubelet, node1 Container image "registry.cn-hangzhou.aliyuncs.com/misa/busybox:1.28" already present on machine
Warning Unhealthy 1m (x19 over 9m) kubelet, node1 Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory
再等30秒,确认容器已经重启: kubectl get pod liveness-exec 从输出结果来RESTARTS值加1了。 NAME READY STATUS RESTARTS AGE liveness-exec 1/1 Running 1 1m