How to edit configmap configuration in spring boot kubernetes application during runtime
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Editing a ConfigMap at runtime is easy. Getting a running Spring Boot application to pick up that new value is the part that usually goes wrong. Kubernetes and Spring Boot solve different parts of the problem: Kubernetes can update mounted ConfigMap files inside a pod, but Spring Boot does not automatically rebind every configuration property just because a file changed.
So the real question has two layers. First, how do you change the ConfigMap object? Second, how does the running application notice and apply the change? If you separate those two concerns, the correct design becomes much clearer.
Update the ConfigMap Object
The operational part is straightforward. You can edit the ConfigMap directly:
Or apply a new manifest:
Then apply it:
That updates the Kubernetes resource, but it does not guarantee your Spring Boot process will instantly refresh its already-bound beans.
Mount the ConfigMap as Files, Not Environment Variables
If you need runtime updates, mount the ConfigMap as a volume. Environment variables are fixed at container start and do not change in the running process.
In Kubernetes, mounted ConfigMap data is eventually updated inside the volume when the ConfigMap changes. One important caveat is that subPath mounts do not receive those live file updates the same way, so avoid subPath if live refresh is a goal.
Make Spring Boot Read From the Mounted Config
Spring Boot still needs to know where the external configuration lives. One option is to import the mounted directory as a config tree.
Or you can mount a whole application.yaml file into a location Boot already reads. The key point is that Boot must treat the mounted files as an external config source.
A simple properties class might look like this:
Binding the property is only half the story, though. If the file changes later, the bean still needs a refresh strategy.
Refreshing the Running Application
A running Boot app will not automatically rebind every property just because a mounted file changed. Common approaches are:
- perform a rollout restart after editing the ConfigMap
- use a refresh mechanism such as Spring Cloud Kubernetes configuration watching
- implement your own file-watching or reloading logic for a narrow set of settings
A rollout restart is often the simplest and most predictable production answer:
If you need near-live refresh without restarting the pod, use an actual refresh architecture. In the Spring ecosystem, that usually means Spring Cloud Kubernetes support plus refresh-aware beans rather than assuming plain Spring Boot property binding will handle it alone.
Choose the Simplest Reliable Model
In many systems, dynamic config sounds attractive but restart-based reload is operationally safer. A restart gives you one clean, auditable transition from old config to new config.
Use true runtime refresh only when the business requirement really demands it. Otherwise, mounted ConfigMap plus controlled rollout is often the better tradeoff.
Common Pitfalls
The biggest mistake is expecting ConfigMap-backed environment variables to change in a running container. They do not.
Another issue is mounting the ConfigMap with subPath and then wondering why updates are not appearing in the mounted file.
A third problem is assuming Spring Boot will automatically refresh already-bound beans when the file changes. Plain property binding does not guarantee that behavior.
Summary
- Editing the ConfigMap object and refreshing a running Spring Boot app are two separate concerns.
- Use volume mounts, not environment variables, if you want the pod filesystem to see ConfigMap updates.
- Avoid
subPathfor live-updating ConfigMap mounts. - Spring Boot needs an explicit refresh strategy if configuration should change without a restart.
- In many production systems, a controlled rollout restart is the simplest and safest way to apply new ConfigMap values.
Related reading
- how to enable api flags in kubernetes
- How to enable Client Certificate Authentication with Traefik Kubernetes?
- How to enable Client Certificate in Google Kubernetes Engine Cluster
- How to enable kube-system/metrics-server from status False MissingEndpoints?
- How to efficiently remove all null elements from a ArrayList or String Array?
- How to enable all endpoints in actuator Spring Boot 2.0.0 RC1
- How to enable Network Policies in Docker for Mac with Kubernetes
- How to enable streaming replication in PostgreSQL running in kubernetes pods?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.