Skip to content

The-Data-Appeal-Company/spring-off

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-off

Download Build codecov license

We hope you and your offspring will gracefully turn off spring using spring-off :)

Graceful shutdown for spring boot in running kubernetes

spring-off allow graceful shutdown of you spring boot based api by handling correctly the SIGTERM signal sent by kubernetes in event of pod termination

How does it work

spring-off intercepts SIGTERM signal sent by kubernetes and then it waits for a fixed amount of time in order to allow the propagation of the iptable configuration that detaches the current pod from the service, in the meanwhile kubernetes may still forward requests to the pod so spring-off take care of waiting for all inflight request to be completed before closing the spring context.

Other libraries also switch off readiness probe before beginning the shutdown procedure, but actually this is not useful in order to improve traffic routing since the pod is already detached from the service when its state is changed to terminating.

Reference:

kubernetes.io - termination-of-pods

graceful shutdown in kubernetes

Integration

Spring

In order to activate the graceful shutdown you must add the @GracefulShutdown and use the GracefulShutdownApp class to start you application

    @GracefulShutdown
    @SpringBootApplication
    public static class MySpringApplication {
        public static void main(String[] args) {
            GracefulShutdownApp.run(MySpringApplication.class, args);
        }
    }

Install

repositories {
    maven {
        url  "https://dl.bintray.com/datappeal/datappeal" 
    }
} 

implementation 'io.datappeal.spring:spring-off:<version>'