Quick revision
The short answer
Spring Boot reads its configuration once, at start-up, and binds it into beans; it does not watch for changes. Environment variables taken from a ConfigMap are fixed for the life of the container, and mounted ConfigMap files do update but nothing tells Boot to rebind them. The usual fix is a rolling restart whenever the configuration changes, often triggered automatically by a checksum annotation; the alternative is a runtime refresh with Spring Cloud Kubernetes, which is more complex and safe only for some settings.
What to remember
In this answer, we saw that Spring Boot binds configuration once at start-up and does not watch for changes. Environment variables from a ConfigMap are fixed for the life of the container, and mounted files update on disk but are not reread. We can roll the pods whenever the configuration changes, automated with a checksum annotation, a hashed ConfigMap name or a reloader, or refresh at runtime with Spring Cloud Kubernetes for the beans that support it. For most settings, restarting on change is the simpler and safer choice.
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.
Spring Boot reads its configuration once, at start-up, and binds it into beans; it does not watch for changes. Environment variables taken from a ConfigMap are fixed for the life of the container, and mounted ConfigMap files do update but nothing tells Boot to rebind them. The usual fix is a rolling restart whenever the configuration changes, often triggered automatically by a checksum annotation; the alternative is a runtime refresh with Spring Cloud Kubernetes, which is more complex and safe only for some settings.
Why this question is asked
This problem surprises people because Kubernetes seems to promise live configuration: we edit the ConfigMap, kubectl confirms the change, and yet the service behaves exactly as before. Interviewers ask it to check whether we know the path a value takes from a ConfigMap into a running JVM, and whether we can choose a sensible way to apply changes. In this answer, we will recap how a ConfigMap reaches a pod, see why environment variables and mounted files behave differently, look at why Spring Boot does not pick up either, and then compare restarting on change with refreshing at runtime.
1A Quick Recap: How a ConfigMap Reaches a Pod
A ConfigMap is a Kubernetes object that stores configuration as key-value pairs. It is not part of the container; the pod refers to it, and the kubelet, the agent on each node that runs pods, copies its values into the container in one of two ways.
The first way is environment variables, using env with configMapKeyRef or envFrom with configMapRef. The kubelet reads the ConfigMap when it creates the container and sets the variables in the new process. The second way is a volume: the kubelet writes each key as a file in a folder inside the container, for example /etc/orders/application.yaml.
2Why Environment Variables Never Change
An environment variable is part of a process. The operating system copies the environment into the process when it starts, and no outside party can change it afterwards. So once the JVM is running, SPRING_DATASOURCE_URL or FEATURE_DISCOUNTS_ENABLED will hold the value it had at container start, whatever happens to the ConfigMap. This is not a Kubernetes limitation that a setting can switch off; it is how processes work.
The value only changes when a new container starts. That is why the standard answer for env-based configuration is always a restart.
3Why Mounted Files Update but Boot Ignores Them
Mounted files are different. The kubelet periodically syncs ConfigMap volumes, so after a short delay, usually up to about a minute depending on the kubelet's sync settings, the file inside the container holds the new content. There is one exception worth remembering: a ConfigMap mounted with subPath never updates, because the file is copied rather than linked.
But Spring Boot read that file during start-up. It loaded the values into its Environment, then bound them into beans: a @ConfigurationProperties class got its fields set, a @Value field got its string, a DataSource was built with the URL. After that, Boot has no file watcher. The new content sits on disk, and the beans keep the values they were given. Even if something did reload the Environment, many values are used only once, such as the pool size of a connection pool that already exists.
5 messages in order. Play them, or step through them one at a time.
Only a restart or an explicit refresh makes Boot read the configuration again.
So the honest description is: the file changed, the application did not. To apply a change, either the process must start again, or something must tell Spring to reread the configuration and rebuild the affected beans.
4Option 1: Restart When the Configuration Changes
The simplest reliable option is to treat a configuration change like a code change and roll the pods. A rolling restart replaces pods one by one, so with enough replicas and a readiness probe there is no downtime, and each new pod reads the new values from scratch.
We can do this by hand with kubectl rollout restart, but it is easy to forget. A common trick automates it: put a hash of the ConfigMap's content into an annotation on the pod template. When the ConfigMap changes, the hash changes, the pod template changes, and Kubernetes rolls the Deployment by itself. With Helm it is one line.
Kustomize reaches the same result differently: its configMapGenerator adds a content hash to the ConfigMap's name, so a change creates a new ConfigMap and updates the reference in the Deployment. Tools such as Reloader, a small controller that watches ConfigMaps and restarts the Deployments that use them, are a third way.
5Option 2: Refresh at Runtime With Spring Cloud Kubernetes
Spring Cloud Kubernetes can read ConfigMaps and Secrets directly through the Kubernetes API and refresh the application when they change. On a refresh, Spring Cloud rebinds @ConfigurationProperties beans and recreates beans marked @RefreshScope, a scope whose beans are thrown away and built again on the next call after a refresh. The trigger can be a reload feature inside the application or a separate Configuration Watcher service that calls the application's refresh endpoint; which options exist and which are recommended has changed between releases, so check your version.
There is a catch. A refresh only reaches beans that know how to be rebuilt. A HikariCP pool, a Kafka consumer or a scheduled task created at start-up will not change its settings. Some instances may refresh and others may not, so for a while the replicas disagree. And the application now needs permission to read ConfigMaps from the API, which widens its security footprint.
| Question | Rolling restart | Spring Cloud Kubernetes refresh |
|---|---|---|
| Settings covered | all of them, including env vars | only rebindable or @RefreshScope beans |
| Consistency | each pod has one known config | replicas may briefly disagree |
| Speed | seconds to minutes, per rollout | seconds |
| Extra parts | a checksum annotation | library, API permissions, refresh trigger |
| Rollback | roll back the release | edit the ConfigMap again |
6Follow-up questions
When would you still choose runtime refresh?
When a value really must change within seconds and a restart is expensive, for example a feature flag or a log level during an incident. Even then, a dedicated feature-flag service or the Actuator loggers endpoint is often a better tool than a general configuration refresh, because it is designed for values that change at runtime.
Why does a file mounted with subPath not update?
A normal ConfigMap volume is a folder whose files are symbolic links to a hidden, versioned folder that the kubelet swaps atomically on update. With subPath, the single file is mounted directly into place, so there is no link to swap and the container keeps the original content until it restarts.
How do you make sure a bad configuration change does not take down every pod?
A rolling restart already helps: with maxUnavailable set low and a readiness probe that fails when the configuration is wrong, the rollout stops after the first bad pod while the old pods keep serving. Validating configuration at start-up with @Validated on @ConfigurationProperties makes a bad value fail fast instead of causing errors later.
7Conclusion
In this answer, we saw that Spring Boot binds configuration once at start-up and does not watch for changes. Environment variables from a ConfigMap are fixed for the life of the container, and mounted files update on disk but are not reread. We can roll the pods whenever the configuration changes, automated with a checksum annotation, a hashed ConfigMap name or a reloader, or refresh at runtime with Spring Cloud Kubernetes for the beans that support it. For most settings, restarting on change is the simpler and safer choice.
Open with
The pods still have the old values because Spring Boot reads configuration once, at start-up, binds it into beans, and never looks again. How the ConfigMap is consumed decides the details.
Then, if they want more
If it is passed as environment variables, those are copied into the process when the container starts and can never change, so only a new container will see the new value.
If it is mounted as a volume, the kubelet does update the files after a short delay, unless subPath was used, but Boot has no file watcher and the beans keep what they were given. So I have two options. The first, which I use by default, is a rolling restart on every config change.
I automate it with a checksum of the ConfigMap in a pod template annotation, so helm upgrade rolls the Deployment by itself, or with Kustomize's hashed ConfigMap names. With readiness probes and a few replicas, it has no downtime, and every pod runs one known configuration.
The second is Spring Cloud Kubernetes with a refresh, which rebinds @ConfigurationProperties and rebuilds @RefreshScope beans. It is faster, but connection pools and consumers do not change, replicas can briefly disagree, and the app needs API permissions, so I keep it for the few values that really need to change live.
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 "A ConfigMap was updated but the running Spring Boot pods still use the old values. Why...": https://scrivio-interview-library.netlify.app/spring-boot/packaging-and-deployment/5498331e01/