'Kubernetes ConfigMap mount single file instead of directory
Is it possible in Kubernetes to mount a file from a ConfigMap into an directory that already has other files? E.g.
Base image filesystem:
/app/
main/
main.py
test.py
ConfigMap contains one file, mounted.py, which should be mounted in /app/main/ alongside main.py and test.py.
Desired filesystem after deployment:
/app/
main/
main.py
test.py
mounted.py
What I have seen so far is that the ConfigMap is mounted to a new directory, so the closest I have come is like this:
/app/
main/
main.py
test.py
mounted/
mounted.py
If I mount the ConfigMap to /app/main, then it clobbers the existing files from the base image. E.g.
/app/
main/
mounted.py
Is there a good way to inject a single file like that? (Actually multiple files in my real use case.) I would prefer not to have separate directories for everything that will be injected by the ConfigMaps, since it deviates from the standard program architecture.
Solution 1:[1]
Use subPath:
volumeMounts:
- name: config
mountPath: /app/main/mounted.py
subPath: mounted.py
The mountPath shows where it should be mounted, and subPath points to an entry inside the volume.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Burak Serdar |
