【问题标题】:Kubernetes ConfigMaps Volume Mount issueKubernetes ConfigMaps 卷挂载问题
【发布时间】:2018-11-21 05:58:39
【问题描述】:

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

我的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

错误

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`

有效

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

此外,configmap 正在以 root 用户身份挂载,因为我们希望卷挂载以特定用户身份进行。

请告诉我我的 yaml 文件中可能缺少什么来解决上述 2 个问题。

【问题讨论】:

  • 能否请您列出您的配置图(或最小示例)?

标签: docker kubernetes mount


【解决方案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

参考地址:https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/

【讨论】:

  • 嗨 Nicola,感谢您的回复,我尝试了上述方法并且容器正在启动,但是 application.properties 文件被第二个卷安装覆盖,因为两者都是同一 mountPath 中的文件夹。
  • 在volumeMounts中使用subPath参数
猜你喜欢
  • 2020-08-07
  • 2019-08-24
  • 2021-10-26
  • 2019-10-09
  • 2018-04-26
  • 2021-04-11
  • 2022-07-21
  • 2017-07-21
  • 2018-08-25
相关资源
最近更新 更多