Search code examples
kubernetes-helm

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?


Solution

  • 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/