terminationGracePeriodSeconds not

5/31/2018

I have a .NET Core console application running in a docker container that I am deploying through Kubernetes. When I update the deployment image, I would like to keep the existing pod around for a while, without accepting new connections, but to keep existing connections alive for a period to allow existing users to finish.

Looking at the Kubernetes docs, I thought that termination grace period seconds was the property to add, but it doesn't seem to be working. As soon as I change the image listed in the deployment then the existing pod is dropped - the grace period is not applied.

Does anyone have any ideas as to what I'm doing wrong in this instance? I can't see anything in the docs.

Bit from my .yml file below:

spec: 
   terminationGracePeriodSeconds: 60
   containers:
       - name: myApplication
-- MrC
.net
docker
kubernetes

3 Answers

11/16/2019

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" ]
-- zeed zhao
Source: StackOverflow

7/10/2018

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.

-- jswidler
Source: StackOverflow

6/1/2018

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.

-- d0bry
Source: StackOverflow