使用 preStop 挂钩时,SIGTERM 何时发送到容器中的 Spring Boot App 进程?

When exactly SIGTERM is sent to Spring Boot App process in a container when preStop hook is used?

我正在尝试了解如何将流量路由到已开始关闭过程的 pod。

在 Spring 引导文档中提到

Once the pre-stop hook has completed, SIGTERM will be sent to the container and graceful shutdown will begin, allowing any remaining in-flight requests to complete.

Kubernetes Container Lifecycle

但是在 Kubernetes 文档中我们有

The 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. No parameters are passed to the handler.

Container hooks

在 Kubernetes 文档中它说 The Pod's termination grace period countdown begins before the PreStop hook is executed 这意味着 SIGTERM 是在调用钩子之前发送的。这与 Spring Boot Once the pre-stop hook has completed, SIGTERM will be sent to the container 相矛盾吗?

它按以下顺序发生:

  1. 终止宽限期开始倒计时
  2. Pre stop hook 开始执行
  3. 预停钩完成
  4. 向容器发出SIGTERM,Spring引导开始关闭(如果配置了优雅关闭可能等待)

如果在任何时间超过宽限期,就会发出 SIGKILL 并终止所有进程。