4

I've seen some examples of helm charts and it looks like some values are encoded to base64 ({{ .Values.name | b64enc }}).
Why and when should it be used?

SagiLow
  • 5,721
  • 9
  • 60
  • 115

1 Answers1

4

In most cases, you will see them used when creating Secret objects. This is because secrets use base64 encoding by default.

You can have a look at a secret in ChartMuseum's stable helm chart to verify.

Another usage is on webhook configurations. Webhook definitions have a caBundle field, which requires a PEM certificate. Since PEM certificates are base64 encoded DER certificates, it is also common to see b64enc there as well. An example from the stable Helm chart of Stash.

You can discover more use cases on the Helm charts repository, by searching for b64enc usages.

Utku Özdemir
  • 7,390
  • 2
  • 52
  • 49
  • Thank you. So the only case where base64 encoded strings are required is when creating a `Secret` and setting its `data`? – SagiLow Aug 16 '19 at 15:43
  • This is the one that I know for sure. But I think it can also be used to put some binary data (maybe from a file), as described here: https://stackoverflow.com/a/49051540/1005102 . Another use case might be label-based matching - if the chart wants to create labels from arbitrary strings, it would need to encode them by base64 - since labels have a syntax requirement: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set – Utku Özdemir Aug 16 '19 at 15:46
  • Interesting. So it can also be used to enforce formating and avoiding deployment failures? Thanks – SagiLow Aug 16 '19 at 15:57
  • 1
    I saw a case case where a custom string needed to be used as a label (annotations were not fitting the use case). A "hack" was to base64 encode it, to meet the label syntax requirements. So, you wouldn't see such usage often, but theoretically it is possible. To generalize it, base64 can be used to as a workaround to fit restrictions on field values of kubernetes objects. – Utku Özdemir Aug 17 '19 at 11:59