2

I need to pass a private RSA key as ENV var to my deployment file, and I can't do it at the moment.

containers:
  env:
      - name: MY_PRIVATE_KEY
        value: |+
        {{ .Values.fpm.dot_env.MY_PRIVATE_KEY}}

I've tried with indent, without indent, using toYaml (there is no error with this but my env var start with |-)...

Any idea?

This is the error I get from that code:

Error: UPGRADE FAILED: YAML parse error on broker-api/templates/deployment.yaml: error converting YAML to JSON: yaml: line 59: could not find expected ':'
OnekO
  • 41
  • 1
  • 8

2 Answers2

2

If you're trying to embed a multi-line string in a Kubernetes artifact in a Helm chart, the easiest recipe is

  1. Use the YAML | block scalar form to preserve newlines;
  2. Start the Go template {{ ... }} macro at the first column; and
  3. Use the sprig indent function to indent every line of the block, including the first one.

(You frequently will see |- which trims the final newline; for this I can imagine wanting to keep the final newline |+ or just plain |; the difference between these last two is whether extra empty lines at the end are kept or not.)

containers:
  env:
      - name: MY_PRIVATE_KEY
        value: |+
{{ .Values.fpm.dot_env.MY_PRIVATE_KEY | indent 12 }}

(Usually for actual secrets it's considered preferable to store them in Kubernetes Secret objects. Those values are base64 encoded in the Kubernetes API, so when you declare the Secret object in Helm you'd use ... | b64enc instead of this indent recipe.)

David Maze
  • 130,717
  • 29
  • 175
  • 215
0

Finally I solved my problem b64encoding my key, and b64decoding it from my backend.

Thanks.

OnekO
  • 41
  • 1
  • 8