Here's how my Helm charts are organized:
helm-charts/
service1/
Chart.yaml
templates/
deployment.yaml
ingress.yaml
service.yaml
values.yaml
service2/
Chart.yaml
templates/
deployment.yaml
ingress.yaml
service.yaml
values.yaml
Now I have a couple of service which nearly share the same template contents, only some settings such as deployment names and deployment endpoints differ.
Is there a way to have a single reusable template across multiple Helm charts?
You can use a --values flag in your Helm commands to override the values in a chart and pass in a new file. Specify the name of the new file after the --values flag in the Helm command. Example: helm upgrade --install <service> -f values.
The above includes a template called toYaml , passes it $value , and then passes the output of that template to the indent function. Because YAML ascribes significance to indentation levels and whitespace, this is one great way to include snippets of code, but handle indentation in a relevant context.
Helm 3 has introduced the concept of „Library Charts“ which allows going DRY (don’t repeat yourself) with Helm charts. From its documentation:
A library chart is a type of Helm chart that defines chart primitives or definitions which can be shared by Helm templates in other charts. This allows users to share snippets of code that can be re-used across charts, avoiding repetition and keeping charts DRY.
The complete manual can be found here: https://helm.sh/docs/topics/library_charts/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With