Spring Boot & Microservices (50 Qs)•Part 2: Persistence, Transactions & Security (11 - 24)
How do you implement graceful shutdown in Spring Boot on Kubernetes?
mid LevelMost AskedCode ExampleState ManagementSecurity & AuthKubernetes
In Simple Words:
When Kubernetes terminates a pod, it sends a SIGTERM signal:
- Configure
server.shutdown: graceful. - Set timeout
spring.lifecycle.timeout-per-shutdown-phase: 30s. - Spring stops accepting new HTTP traffic and allows in-flight requests and background jobs up to 30 seconds to finish before terminating.
Configuration (application.yml)
yaml
server:
shutdown: graceful # Stops accepting new connections, allows in-flight requests to complete
spring:
lifecycle:
timeout-per-shutdown-phase: 30s # Maximum grace period before SIGKILL
Configuration (application.yml)
yaml
server:
shutdown: graceful # Stops accepting new connections, allows in-flight requests to complete
spring:
lifecycle:
timeout-per-shutdown-phase: 30s # Maximum grace period before SIGKILL