kubernetes preStop gracefull shutdown timeout without hook

7/25/2021

I want to set the parameter

terminationGracePeriodSeconds

to some value so that kubernetes will let my pods finish their work. I know that normaly you will use this parameter combined with a preStop hook of type http or exec, but what if I only set this parameter without any hook? will Kubernetes still wait for the terminationGracePeriodSeconds before it removes the container?

-- toto
kubernetes

1 Answer

7/25/2021

There is no actual coupling between terminationGracePeriodSeconds spec and a definition of a preStop and you can define the pod.Spec.TerminationGracePeriodSeconds value to your custom needs per-container.

Meanwhile, the value to which the graceful shutdown period is set will affect the time left for your container to terminate gracefully when you have a preStop hook configured as the both execute in a synchronous serial fashion and the total time specified in the terminationGracePeriodSeconds includes the preStop hook execution time.

As an example, if you specify 30 (seconds) as the terminationGracePeriodSeconds value and the preStop hook takes 25 seconds to terminate, then the container is left with only 5 seconds to terminate gracefully before being shutdown abruptly by the Kubernetes Manager.

-- tmarwen
Source: StackOverflow