Kubernetes ConfigMaps 卷挂载问题

Ama*_*ala 5 mount docker kubernetes

我无法使用多文件夹卷挂载来挂载配置映射。

我的结构volume-mount.yaml如下:

不起作用

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
Run Code Online (Sandbox Code Playgroud)

错误

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`
Run Code Online (Sandbox Code Playgroud)

作品

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
Run Code Online (Sandbox Code Playgroud)

此外,configmap 是以 root 用户身份安装的,而我们希望卷安装以特定用户身份进行。

您能否让我知道我的 yaml 文件中可能缺少什么来解决上述两个问题。

Nic*_*Ben 1

对于你的情况,这应该很合适:

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
Run Code Online (Sandbox Code Playgroud)

参考位于: https: //kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/

  • 在volumeMounts中使用subPath参数 (2认同)