简体   繁体   English

Kubernetes ConfigMaps 卷挂载问题

[英]Kubernetes ConfigMaps Volume Mount issue

I am unable to mount a configmap using multi-folder volume mount.我无法使用多文件夹卷挂载来挂载 configmap。

The structure of my volume-mount.yaml is below:我的volume-mount.yaml的结构如下:

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.此外,configmap 以 root 用户身份安装,因为我们希望以特定用户身份安装卷。

Can you please let me know what i may be missing in my yaml file to fix the above 2 issues.您能否让我知道我的 yaml 文件中可能缺少什么来解决上述 2 个问题。

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/参考在: https : //kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM