首页 > 解决方案 > 无法为 volumeMount 准备 subPath

问题描述

收到此错误。

Error: failed to prepare subPath for volumeMount "solr-collection-config" of container "upload-config-container"

使用 Kubernetes 1.10.11

- name: upload-config-container image: solr:7.4.0-alpine imagePullPolicy: Always resources: requests: memory: "128Mi" cpu: "100m" limits: memory: "256Mi" cpu: "200m" volumeMounts: - name: solr-collection-config mountPath: /tell/carbon/conf subPath: conf

solr-collection-config是一个表示 ConfigMap 的卷

volumes: - name: solr-collection-config configMap: name: solr-collection-resources items: - key: stopwords_en.txt path: "conf/lang/stopwords_en.txt" - key: _rest_managed.json path: "conf/_rest_managed.json" - key: currency.xml path: "conf/currency.xml" - key: protwords.txt path: "conf/protwords.txt" - key: schema.xml path: "conf/schema.xml" - key: solrconfig.xml path: "conf/solrconfig.xml" - key: stopwords.txt path: "conf/stopwords.txt" - key: synonyms.txt path: "conf/synonyms.txt" restartPolicy: Never

非常感谢您的帮助。谢谢

标签: kubernetesconfigmap

解决方案


如果不使用会发生什么subPath

configMap中的所有键都将挂载在 directory 中/tell/carbon/conf。这意味着,每个键都将是该目录下的一个单独文件。

现在,这subPath是做什么的?从你的例子中,

volumeMounts:
  - name: solr-collection-config
    mountPath: /tell/carbon/conf
    subPath: conf

意味着,conf来自configMap的密钥将作为文件挂载到目录conf/tell/carbon

但是,您没有这把钥匙。所以得到这个错误。

错误:无法为容器“upload-config-container”的volumeMount“solr-collection-config”准备子路径

现在,你可以这样做

volumeMounts:
  - name: solr-collection-config
    mountPath: /tell/carbon/conf
    subPath: stopwords_en.txt

这意味着,stopwords_en.txt来自您的configMap的值将作为conf文件挂载在/tell/carbon.

最后的话,这subPath实际上是从数据量到数据来源的路径。在您的情况下,subPath应该是您的configMap中的关键之一


推荐阅读