after kubernetes preStop hook, is terminationGracePeriodSeconds still honored?

309 Views Asked by At

I have a preStop hook for my pod that sends TSTP signals to each process, and waits for their completion, but only to a maximum of 60 seconds.

Let us say that we set terminationGracePeriodSeconds to 3600 seconds. After the completion of the preStop hook, shouldn't it now send the TERM signal to my processes, and wait until the expiry of terminationGracePeriodSeconds before finally sending the KILL signal?

Because now it seems that after the completion of the preStop hook, it immediately sends a KILL signal and my pod is deleted abruptly, even when there is still a process running.

1

There are 1 best solutions below

2
Will On

No, it won't wait for the terminationGracePeriodSeconds.

This is the intended behavior for the preStop hook to send a SIGTERM on completion.

In case the preStop hook isn't finished after terminationGracePeriodSeconds countdown, kubelet will request 2 extra seconds for it to complete and then will send a SIGKILL to force the pod to shutdown.

The full sequence is :

  1. pod deletion has been requested
  2. preStop hook kicks in and terminationGracePeriodSeconds countdown starts :
    • if preStop hook completes, it sends a SIGTERM which stops the pods
    • if preStop hook isn't finished within terminationGracePeriodSeconds countdown, kubelet request 2 extra seconds before sending the SIGKILL which will stops the pod.

enter image description here

Sources :