Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse Helm templates across charts?

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?

like image 877
Lars Blumberg Avatar asked Jun 16 '20 17:06

Lars Blumberg


People also ask

How do you override a Helm chart?

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.

What does toYaml do in Helm?

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.


1 Answers

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/

like image 182
Lars Blumberg Avatar answered Oct 27 '22 11:10

Lars Blumberg