简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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