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

1/11/2018

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?

-- Daniel Sagayaraj
kubernetes
kubernetes-helm

1 Answer

4/25/2018

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
-- abinet
Source: StackOverflow