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

Time:04-07

I'm trying to understand how traffic can be routed to a pod that has begun shutdown process.

In Spring Boot docs it is mentioned that

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

But in Kubernetes docs we have

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

In Kubernetes docs it say The Pod's termination grace period countdown begins before the PreStop hook is executed which means SIGTERM was send before the hook is called. Isn't this in contradiction to Spring Boot which says Once the pre-stop hook has completed, SIGTERM will be sent to the container?

CodePudding user response:

It happens in the following order:

  1. Count down for termination grace period starts
  2. Pre stop hook starts executing
  3. Pre stop hooks finished
  4. SIGTERM is issued to the container, Spring Boot starts shutting down (possible waiting if graceful shutdown is configured)

If at any point in time the grace period is exceeded SIGKILL is issued and all processes are terminated.

  • Related