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" ]
I was looking for something, so I added some logging that help to see the logs of the script in the pod's stdout/stderr logs.
so for me, this approach help me
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "/clean.sh > /proc/1/fd/1"]
and was able to verify the logs
kubectl get pods
kubectl logs -f my_stohook_pod
/proc/PID/fd/1
will help us to redirect script logs stdout/stderr of the container main process.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With