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 over
You cannot mount two ConfigMaps to the same location.
But mentioning subPath
and key
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:
apiVersion: v1
kind: Pod
metadata:
name: config-single-file-volume-pod
spec:
containers:
- name: test-container
image: gcr.io/google_containers/busybox
command: [ "/bin/sh", "-c", "cat /etc/special-key" ]
volumeMounts:
- name: config-volume-1
mountPath: /etc/special-key1
subPath: path/to/special-key1
- name: config-volume-2
mountPath: /etc/special-key2
subPath: path/to/special-key2
volumes:
- name: config-volume-1
configMap:
name: test-configmap1
items:
- key: data-1
path: path/to/special-key1
- name: config-volume-2
configMap:
name: test-configmap2
items:
- key: data-2
path: path/to/special-key2
restartPolicy: Never
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:
apiVersion: v1
kind: Pod
metadata:
name: config-single-file-volume-pod
spec:
containers:
- name: test-container
image: gcr.io/google_containers/busybox
command: [ "/bin/sh", "-c", "cat /etc/special-key" ]
volumeMounts:
- name: config-volume-1
mountPath: /etc/special-keys
subPath: cm1
- name: config-volume-2
mountPath: /etc/special-keys
subPath: cm2
volumes:
- name: config-volume-1
configMap:
name: test-configmap1
- name: config-volume-2
configMap:
name: test-configmap2
restartPolicy: Never
cm1
and cm2
will be two directories containing files derived from keys in test-configmap1
and test-configmap2
respectively.