terminationGracePeriodSeconds not terminationGracePeriodSeconds not docker docker

terminationGracePeriodSeconds not


The way the grace period works is that the main docker process is immediately sent a SIGTERM signal, and then it is allowed a certain amount of time to exit on its own before it is more forcefully shutdown. If your app is quitting right away, it is because it quits when it gets this signal.

Your app could catch the SIGTERM signal, and then quit on its own after all the open operations complete. Or it could catch the SIGTERM signal and just do nothing and wait for it to be forced down a different way.


Sharing a solution, the authors evaluated several conjectures based on the Kubernetes documentation and verified them one by one.

  containers:  - name: containername    lifecycle:      preStop:        exec:          command: [ "/bin/sleep", "20" ]


Each container has its lifecycle. You can manage the shutdown process with Lifecycle Hooks.

I may recommend you checking if the PreStop hook fits your needs.

The PreStop hook is called immediately before a container is terminated. It is blocking, meaning it is synchronous, so it must complete before the call to delete the container can be sent. No parameters are passed to the handler.

You can use shell script or call http request at the time when PreStop hook is started.

Kubernetes documentation describes termination of pods and I find it useful.