I have a worker pod that subscribes to a service queue. We need to define the liveness probe to monitor worker health. the worker pod doesn't expose any HTTP or TCP port. So I use the command to check worker health. like this.
livenessProbe:
exec:
command:
- cat
- log/healthy-2020-07-16-03.log
Every 5s, worker pod will output health info to log file. logfile name format is healthy-YYYY-MM-DD-HH.log. And each log info is like:
{"message":"Thu Jul 16 2020 03:23:30 GMT+0000 (Coordinated Universal Time) health","level":"notice","Env":"local","Service":"myservice","timestamp":"2020-07-16T03:23:30.008Z"}
So I need to check the log timestamp and message for healthy.
My question is:
Is my approach follow the best practice of k8s health probe?
Yes
Does k8s support more powerful command? eg: python script or jq. I need to parse JSON and validate timestamp and message?
Actually, exec probe will be running as a command line inside the container. More details here. So it is upto you to run anything like a python script or jq. However, you have to ensure that the command you are running in the probe can be executed inside the container. Say for example, you want to run a python script for the probe, ensure your container has python installed and the script also present inside the container.
For worker pod, we don't need to define readiness probe, because it doesn't bind with k8s service or endpoint, right?
That depends on your use case and how your service works.
A nice article here explaining the readiness & liveness probe.