I'm trying to use pod's lifecycle event. Problem is that command from preStop
doesn't run at all. Is there any way to monitor if it was started? Log of the container is empty.
lifecycle:
preStop:
exec:
command: [ "/bin/sh", "-c", "/clean.sh" ]
From https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#debugging-hook-handlers
The logs for a Hook handler are not exposed in Pod events. If a handler fails for some reason, it broadcasts an event. [...] For
PreStop
, this is theFailedPreStopHook
event. You can see these events by runningkubectl describe pod <pod_name>
. Here is some example output of events from running this command [...]
I just want to add for the preStop
hook, the pod may be terminated and not available to describe
.
Another way to see the preStop
error log is via kubectl events:
kubectl get events | grep FailedPreStopHook
Example:
kubectl get events | grep FailedPreStopHook
5m33s Warning FailedPreStopHook pod/pod-name-59988c4675-79q4p
Exec lifecycle hook ([/bin/kill -s SIGQUIT 1]) for Container "container_name" in Pod "pod-name-59988c4675-79q4p_namespace(556dc3d2-9da4-11ea-bca3-00163e01eb9a)" failed - error:
command '/bin/kill -s SIGQUIT 1' exited with 1: kill: can't kill pid 1: Operation not permitted