How to use key value pair in kubernetes configmaps to mount volume

倖福魔咒の 提交于 2020-01-25 09:32:44

问题


I have created a kubernetes configmap which contains multiple key value pairs. I want to mount each value in a different path. Im using helm to create charts.

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Values.name }}-configmap
  namespace: {{ .Values.namespace }}
  labels:
    name: {{ .Values.name }}-configmap
data:
    test1.yml: |-
  {{ .Files.Get .Values.test1_filename }}

    test2.yml: |-
  {{ .Files.Get .Values.test2_filename }}

I want test1.yml and test2.yml to be mounted in different directories.How can i do it?


回答1:


You can use subPath field to pickup specific file from configMap:

  volumeMounts:
  - mountPath: /my/first/path/test.yaml
    name: configmap
    subPath: test1.yaml
  - mountPath: /my/second/path/test.yaml
    name: configmap
    subPath: test2.yaml


来源:https://stackoverflow.com/questions/48201065/how-to-use-key-value-pair-in-kubernetes-configmaps-to-mount-volume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!