Multiline Properties in kubernetes Helm with ConfigMaps

nordvpn best offer nordvpn best offer


There are several APIs in Kubernetes. A ConfigMap is one of these. It is an object which helps to storing some non-confidential data. The data is in the form of key-value pairs. Some use envrionment variables. In this blog post, we will see how you can show multi-value lines.

Working with Kubernetes Helm, I went to the documentation. The link to the documentation is here.

In Helm’s v3 documentation, in the section Accessing Files Inside Templates, you have an example of 3 properties (toml) files; where each file has only one key/value pair.

The configmap.yaml looks like this. It contains one config.toml for simplicity.

apiVersion: v1
kind: ConfigMap
  name: {{ .Release.Name }}-config
  {{- $files := .Files }}
  {{- range tuple "config.toml" }}
  {{ . }}: |-
    {{ $files.Get . }}
  {{- end }}

I was happy with it. Then I add a second line to the config.toml file.



Then boom, I get an Error:

INSTALLATION FAILED: YAML parse error on deploy/templates/configmap.yaml: error converting YAML to JSON: yaml: line 9: could not find expected ':'

Digging in this error, I found a solution.

The solution

Helm will read in that file, but as it is a text templating engine, It does not understand that I was trying to compose a YAML file.

As a consquence, it was not helping me in the error.

That’s actually why you will see so many, many templates in the wild with

{{ .thing | indent 8 }}


{{ .otherThing | toYaml }}

– because you need to help Helm know in what context it is emitting the text.

So, in my specific case, I needed to indent the filter with a value of 4 because mycurrent template has two spaces for the key indent level, and two more spaces for the value block scalar


  {{- $files := .Files }}
  {{- range tuple "config.toml" }}
  {{ . }}: |-
{{ $files.Get . | indent 4 }}
{{/* notice this ^^^ template expression is flush left,
because the 'indent' is handling whitespace, not the golang template itself */}}
  {{- end }}

I hope this quick post will help someone in his research. Helm is a very powerfull tool in the Kubernetes world. It is very useful when building code-server on Digital Ocean.

Inspiration from this post.

Full Bright

Full Bright

A professional and sympathic business man.


Contact Us

To order one of our services, navigate to the order service page


10 rue de Penthièvre,
75008 Paris

Email Us

hello at bright-softwares dot com

Open Hours

Monday - Friday
9:00AM - 05:00PM