spring-boot 2 graceful shutdown web spring-boot 2 graceful shutdown web kubernetes kubernetes

spring-boot 2 graceful shutdown web


If you are on the latest version of spring-boot i.e. 2.3.5.RELEASE, then all you need to do it add the below properties to the application.properties file and you are done.

server.shutdown=gracefulspring.lifecycle.timeout-per-shutdown-phase=30s

In Kubernetes world, you can use the preStop hook. But use this when you actually want a hold before SIGTERM is initiated.

This hook is called immediately before a container is terminated. No parameters are passed to the handler. This event handler is blocking, and must complete before the call to delete the container is sent to the Docker daemon. The SIGTERM notification sent by Docker is also still sent. A more complete description of termination behavior can be found in Termination of Pods.