它如何为 pod 中的容器创建关闭序列?
How do it create a shutdown sequence for containers in a pod?
当从 k8s 收到 SIGTERM 信号时,我希望我的 sidecar 仅在主容器完成后停止运行。如何为关闭例程创建依赖链?
我可以使用 preStop
并等待 120 秒,但要清理 pods 将持续 120 秒。
我想知道我的边车是否有办法检查我的主容器是否被杀死。或者主容器是否有可能在完成清理后向我的边车发出信号(通过 k8s 而不是我的主容器中的代码更改。
在您的 preStop
挂钩中,检查您的主容器是否仍然 运行(而不是仅仅等待一段固定的时间。
如果主容器有一个现有的 healthprobe(例如一个 http 端点),您可以从 preStop
挂钩中调用它。
另一种选择是编辑主容器中的入口点脚本以包含一个 trap 命令,该命令在关闭时创建一个文件。 preStop
sidecar 的挂钩等待此文件出现。
trap "touch /lifecycle/main-pod-terminated" SIGTERM
如果使用 preStop 挂钩,只需 keep the grace period countdown in mind 并在需要时通过设置适当的 terminationGracePeriodSeconds
值来增加默认值(30 秒)
Pod's termination grace period countdown begins before the preStop
hook is executed, so regardless of the outcome of the handler, the
container will eventually terminate within the Pod's termination grace
period
当从 k8s 收到 SIGTERM 信号时,我希望我的 sidecar 仅在主容器完成后停止运行。如何为关闭例程创建依赖链?
我可以使用 preStop
并等待 120 秒,但要清理 pods 将持续 120 秒。
我想知道我的边车是否有办法检查我的主容器是否被杀死。或者主容器是否有可能在完成清理后向我的边车发出信号(通过 k8s 而不是我的主容器中的代码更改。
在您的 preStop
挂钩中,检查您的主容器是否仍然 运行(而不是仅仅等待一段固定的时间。
如果主容器有一个现有的 healthprobe(例如一个 http 端点),您可以从 preStop
挂钩中调用它。
另一种选择是编辑主容器中的入口点脚本以包含一个 trap 命令,该命令在关闭时创建一个文件。 preStop
sidecar 的挂钩等待此文件出现。
trap "touch /lifecycle/main-pod-terminated" SIGTERM
如果使用 preStop 挂钩,只需 keep the grace period countdown in mind 并在需要时通过设置适当的 terminationGracePeriodSeconds
Pod's termination grace period countdown begins before the
preStop
hook is executed, so regardless of the outcome of the handler, the container will eventually terminate within the Pod's termination grace period