Search code examples
kubernetes-helmconfigmap

Set ConfigMap values directly from values.yaml in helm


I am trying to build ConfigMap data directly from values.yaml in helm

My Values.yaml

myconfiguration: |-
key1: >
  { "Project" : "This is config1 test"
  }
key2 : >
  {
    "Project" : "This is config2 test"
  }

And the configMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: poc-secrets-configmap-{{ .Release.Namespace }}
data:
{{.Values.myconfiguration | indent 1}} 

But the data is empty when checked on the pod

Name:         poc-secrets-configmap-xxx
Namespace:    xxx
Labels:       app.kubernetes.io/managed-by=Helm
Annotations:  meta.helm.sh/release-name: poc-secret-xxx
              meta.helm.sh/release-namespace: xxx

Data
====
Events:  <none>

Can anyone suggest


Solution

  • You are missing indentation in your values.yaml file, check YAML Multiline

    myconfiguration: |-
      key1: >
        { "Project" : "This is config1 test"
        }
      key2 : >
        {
          "Project" : "This is config2 test"
        }
    

    Also, the suggested syntax for YAML files is to use 2 spaces for indentation, so you may want to change your configmap to {{.Values.myconfiguration | indent 2}}