I am having two different config maps test-configmap and common-config. I tried to mount them at the same location, but one config map overwrote the other. Then I read about subPath
and did not work.
deploy.yaml
apiVersion: apps/v1beta1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: testing
spec:
replicas: 1
template:
metadata:
name: testing
labels:
app: testing
spec:
containers:
- name: testing-container
image: testing
imagePullPolicy: IfNotPresent
ports:
- containerPort: __PORT__
volumeMounts:
- name: commonconfig-volume
mountPath: /usr/src/app/config/test.config
subPath: test.config
volumes:
- name: commonconfig-volume
configMap:
name: test-configmap
- name: commonconfig-volume
configMap:
name: common-config
Error :
The Deployment "testing" is invalid: spec.template.spec.volumes[1].name: Duplicate value: "commonconfig-volume"
I am not sure if merging two config map achievable of not. And if yes then how should I do it.
Another example of how this can be done for mounting multiple configmaps. This for an nginx dock were you want to both replace the main /etc/nginx/nginx.conf and the files in /etc/nginx/conn.f. This also deletes the default.conf file in conf.d
And one very important point. If you have any out commented lines (# something) in your yaml file, then this will not work. It's a bug. Tested in kubectl v1.14
You have to use special projected volumes for achieve that. Example your deployment:
You can use
secret
same asconfigMap
You cannot mount two ConfigMaps to the same location.
But mentioning
subPath
andkey
for every item in each configmaps will let you get items from both configmaps in the same location. You'll have to write mount points for each file manually:Another way is to mount them under same directory, but different subPath so that you don't have to specify items by hand. But, here keys from each configmap will be put into two different directories:
cm1
andcm2
will be two directories containing files derived from keys intest-configmap1
andtest-configmap2
respectively.One way would be to mount them at different points but in the same
emptyDir
volume, mounting that same volume into an init container and including a short script in the init container to merge the two files using whatever tools you install at the start of the script. Scripts can easily be included in the pod manifest using the technique in this answer.