Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

terminationGracePeriodSeconds not

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
like image 626
MrC Avatar asked May 31 '18 15:05

MrC


2 Answers

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.

like image 57
d0bry Avatar answered Sep 26 '22 19:09

d0bry


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.

like image 30
jswidler Avatar answered Sep 23 '22 19:09

jswidler