Skip to main content
InterviewHubPRO
Section Overview
Q15

Question 15 of 50

Part 2: Persistence, Transactions & Security (11 - 24)

30%
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:

  1. Configure server.shutdown: graceful.
  2. Set timeout spring.lifecycle.timeout-per-shutdown-phase: 30s.
  3. 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