Demo: Liveness Command
ฝัง
- เผยแพร่เมื่อ 10 ก.ค. 2024
- Welcome to the liveness probe demo.
In this video, we are running the liveness-exec pod presented on the previous page of this chapter to show how we check the health of an application container using the liveness command.
Let's review the yaml manifest.
In the manifest, we define a pod that runs a busybox container.
The container is configured to create a /tmp/healthy file upon startup, sleep for 30 seconds, then remove the /tmp/healthy file.
The probe is configured to cat the /tmp/healthy file every 5 seconds
after an initial delay of 3 seconds.
The first few cat commands will be successful,
but once the file is removed by the busybox script after 30 seconds, the probe will fail.
By default, kubelet would wait to reach the default failure threshold of three consecutive failures before declaring the container unhealthy and restarting it.
In our example, the failure threshold property is set to 1, meaning that after a single failed probe,
the container is declared unhealthy and it is started or restarted by kubelet.
So, let's run the pod,
and then monitor its behavior more precisely keeping an eye on the number of restarts.
There are several commands that can help,
such as kubectl get pod,
where the -w flag performs a watch and automatically refreshes the output with every container restart.
Run it once and wait for a few minutes to see the results.
We can also run the kubectl get pod command manually, run it every few minutes or so,
or the kubectl describe pod command.
Again, we can run this every minute or so and scroll down to the events section
to see both successful and failed scheduling events.
So, in this demo, we learned how to configure a liveness probe with the liveness command,
which reacted to an event and triggered a container restart once declared unhealthy.
Thank you for watching and I will see you in the next video.