Kurbernetes ConfigMaps Volume Mount issue

6/11/2018

I am unable to mount a configmap using multi-folder volume mount.

The structure of my volume-mount.yaml is below:

DOESN'T WORK

apiVersion: v1
kind: Pod
metadata:
  name: test-web
spec:
  containers:
    - name: test-web
      image: docker.io/hello-world    
      volumeMounts:
      - name: config-volume
        mountPath: /usr/test
  volumes:
    - name: config-volume
      configMap:
        name: test-config-map
        items:
       - key: application.properties 
         path: test-web
       - key: test.xml
          path: test-web/configs/test_config
  restartPolicy: Never

Error:

MountVolume.SetUp failed for volume "config-volume" : open /var/lib/kubelet/pods/93768c34-6dc6-11e8-9546-025000000001/volumes/kubernetes.io~configmap/config-volume/..2018_06_11_22_27_08.476420050/test-web: is a directory`

WORKS

apiVersion: v1
kind: Pod
metadata:
  name: test-web
spec:
  containers:
    - name: test-web
      image: docker.io/hello-world    
      volumeMounts:
      - name: config-volume
        mountPath: /usr/test
  volumes:
    - name: config-volume
      configMap:
        name: test-config-map
        items:
       - key: test.xml
          path: test-web/configs/test_config
  restartPolicy: Never

Also the configmap is getting mounted as root user where as we want the volume mount to happen as a specific user.

Can you please let me know what i may be missing in my yaml file to fix the above 2 issues.

-- Amala
docker
kubernetes
mount

1 Answer

6/12/2018

In your case this should fit well:

apiVersion: v1
kind: Pod
metadata:
  name: test-web
spec:
  containers:
    - name: test-web
      image: docker.io/hello-world
      volumeMounts:
      - name: config-volume-1
        mountPath: /usr/test1
      - name: config-volume-2
        mountPath: /usr/test2
  volumes:
    - name: config-volume-1
      configMap:
        name: test-config-map
        items:
        - key: application.properties 
          path: test-web
    - name: config-volume-2
      configMap:
        name: test-config-map
        items:
        - key: test.xml
          path: test-web/configs/test_config
  restartPolicy: Never

Reference is at: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/

-- Nicola Ben
Source: StackOverflow