Quick revision
The short answer
The settings that matter most are the readiness, liveness and startup probes, graceful shutdown (a preStop hook and a long enough termination grace period), CPU and memory requests and limits, and how configuration and secrets reach the application. Spring Boot helps with each: it detects that it runs on Kubernetes and enables the liveness and readiness health groups at /actuator/health/liveness and /actuator/health/readiness, it supports graceful shutdown of the web server, the JVM sizes its heap from the container's memory limit, and Boot reads configuration from environment variables and mounted files.
What to remember
In this answer, we went through the Kubernetes settings that matter most for a Spring Boot service: readiness, liveness and startup probes, which Boot supports through its liveness and readiness health groups enabled automatically on Kubernetes; graceful shutdown with a preStop delay and a grace period longer than Boot's shutdown timeout; equal memory requests and limits with the heap sized as a percentage of the container limit; and configuration and secrets supplied through environment variables or mounted files read with configtree.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The settings that matter most are the readiness, liveness and startup probes, graceful shutdown (a preStop hook and a long enough termination grace period), CPU and memory requests and limits, and how configuration and secrets reach the application. Spring Boot helps with each: it detects that it runs on Kubernetes and enables the liveness and readiness health groups at /actuator/health/liveness and /actuator/health/readiness, it supports graceful shutdown of the web server, the JVM sizes its heap from the container's memory limit, and Boot reads configuration from environment variables and mounted files.
Why this question is asked
Kubernetes can only run a service well if the service tells it the truth: when it is ready for traffic, when it is broken, how much it needs and how to stop it cleanly. Most production problems with Spring Boot on Kubernetes, such as errors during every deployment, restart loops at start-up and OOMKilled pods, come from getting one of these wrong. Interviewers ask this to see whether we know the handful of settings that matter and how Boot supports them. In this answer, we will go through probes, graceful shutdown, resources and the JVM, and configuration, with a small manifest at the end.
1Probes: Readiness, Liveness and Startup
Kubernetes uses three probes, each an HTTP call or command it runs periodically. The readiness probe answers "should this pod receive traffic now?"; when it fails, the pod is removed from the Service's endpoints but keeps running. The liveness probe answers "is this pod broken beyond repair?"; when it fails repeatedly, Kubernetes restarts the container. The startup probe protects slow starters: until it succeeds, the other two are not run, so a JVM that needs 40 seconds to start is not killed by a liveness probe after 10.
Spring Boot maps these onto its application availability states. When it detects Kubernetes, through the KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT environment variables that every pod gets, it enables two health groups: liveness, reflecting whether the application's internal state is correct, and readiness, which becomes ACCEPTING_TRAFFIC only after the application has fully started and switches to REFUSING_TRAFFIC when shutdown begins. Outside Kubernetes we can turn them on with management.endpoint.health.probes.enabled=true.
One rule matters more than any other here: the liveness check must not depend on external systems. If liveness included the database health and the database had a two-minute outage, Kubernetes would restart every pod of the service, turning a dependency outage into a full restart storm. Boot's liveness group by default contains only the liveness state for exactly this reason. Database checks may go into readiness, carefully, or nowhere.
2Graceful Shutdown
During a rolling deployment, Kubernetes stops old pods. It sends SIGTERM to the container, waits up to terminationGracePeriodSeconds (30 seconds by default), and then kills it. At the same time, and not in a guaranteed order, it removes the pod from the Service endpoints, and that removal takes a few seconds to reach every node and load balancer. So for a short time after SIGTERM, requests still arrive.
Two settings handle this. A preStop hook that sleeps for a few seconds delays the SIGTERM until the endpoint removal has spread. Then Spring Boot's graceful shutdown, server.shutdown=graceful (the default in recent Boot versions; check yours), stops accepting new connections and lets in-flight requests finish, for up to spring.lifecycle.timeout-per-shutdown-phase, 30 seconds by default. The grace period must cover both: preStop sleep plus the shutdown timeout plus a margin.
6 messages in order. Play them, or step through them one at a time.
terminationGracePeriodSeconds must be longer than preStop plus the shutdown timeout.
3CPU and Memory: Requests, Limits and the JVM
Requests are what the scheduler reserves for the pod on a node; limits are the maximum the container may use. Exceeding the memory limit gets the container OOMKilled by the kernel; exceeding the CPU limit gets it throttled. For Java, memory requests and limits are usually set equal, so the pod's memory is guaranteed and predictable.
The JVM is container-aware: it reads the cgroup memory limit and CPU quota at start-up. By default it sets the maximum heap to 25 percent of the container's memory, which is very conservative for a dedicated container. We set -XX:MaxRAMPercentage=75 instead of a fixed -Xmx, so the heap scales with the limit and leaves a quarter for metaspace, thread stacks, code cache and direct buffers. The CPU limit also matters: the JVM uses it to decide how many processors it has, which sizes GC threads, the common ForkJoinPool and, with fewer than 2 CPUs or less than about 1792 MB, makes the JVM pick the Serial collector instead of G1.
4Configuration and Secrets
The last group is how the application gets its settings. Kubernetes offers ConfigMaps and Secrets, which can be exposed as environment variables or as files mounted into the container. Boot reads both without any Kubernetes-specific code: environment variables map onto properties through relaxed binding, so SPRING_DATASOURCE_URL sets spring.datasource.url, and mounted directories can be imported with spring.config.import=configtree:/etc/config/, which turns each file name into a property name and its content into the value.
Mounted files are usually better for secrets: they are not visible in the process environment or in crash dumps that print it, and Kubernetes updates them when the Secret changes, which env vars never see. Either way, the image contains no environment-specific configuration, so the same image runs in every environment.
5Putting It Together in a Manifest
Here is the relevant part of a Deployment, combining the probes, shutdown, resources and configuration.
If the image has no shell, recent Kubernetes versions offer a sleep action for preStop hooks that needs no binary in the image (check your cluster version). And if the management endpoints run on a separate port, the probes must point at that port; Boot can also expose /livez and /readyz on the main port with management.endpoint.health.probes.add-additional-paths=true.
6Follow-up questions
Why not use /actuator/health for all probes?
The full health endpoint includes every health indicator, such as the database, Redis and disk space. Using it for liveness means a dependency outage restarts all pods; using it for readiness means a slow cache can take every pod out of the load balancer at once. The dedicated liveness and readiness groups contain only the application's own state unless we add indicators deliberately.
Should we set a CPU limit?
Opinions differ. A CPU limit causes throttling, which hurts latency, especially at start-up when the JIT and class loading need a lot of CPU. Many teams set a CPU request, so the scheduler reserves capacity and the JVM sees a sensible processor count, and no CPU limit, or a generous one. If there is no limit, setting -XX:ActiveProcessorCount keeps the JVM's thread sizing predictable.
What happens if terminationGracePeriodSeconds is too short?
Kubernetes sends SIGKILL when the grace period ends, even if requests are still in flight or Spring is still closing connections. Clients see reset connections or 502 errors on every deployment. The grace period must be longer than the preStop delay plus Boot's shutdown phase timeout.
7Conclusion
In this answer, we went through the Kubernetes settings that matter most for a Spring Boot service: readiness, liveness and startup probes, which Boot supports through its liveness and readiness health groups enabled automatically on Kubernetes; graceful shutdown with a preStop delay and a grace period longer than Boot's shutdown timeout; equal memory requests and limits with the heap sized as a percentage of the container limit; and configuration and secrets supplied through environment variables or mounted files read with configtree.
Open with
I would start with the probes, since they decide traffic and restarts. Spring Boot detects Kubernetes from the service environment variables every pod gets and enables two health groups, /actuator/health/liveness and /actuator/health/readiness.
Then, if they want more
Readiness only becomes UP after the application has fully started and goes down when shutdown begins, and I point the readiness probe at it.
Liveness reflects only the application's own state, so a database outage never causes a restart storm, and I add a startup probe on the same endpoint with a generous failure threshold so slow JVM start-up is not killed.
Second, graceful shutdown: Kubernetes removes the pod from endpoints and sends SIGTERM at the same time, so I add a preStop sleep of about ten seconds, keep Boot's graceful server shutdown with its thirty-second phase timeout, and set terminationGracePeriodSeconds above the sum, say forty-five.
Third, resources: memory request equal to the limit, and the heap set with MaxRAMPercentage around seventy-five instead of a fixed Xmx, because the JVM reads the container limit and otherwise only takes twenty-five percent. The CPU setting also drives the JVM's thread counts and GC choice.
Finally, configuration comes from env vars or mounted ConfigMaps and Secrets, which Boot reads with relaxed binding and configtree imports, so the same image runs everywhere.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Boot reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Which Kubernetes settings matter most for a Spring Boot service, and how does Boot help...": https://scrivio-interview-library.netlify.app/spring-boot/packaging-and-deployment/6289c3ec3e/