47

I have ~20 yamls in my helm chart + tons of dependencies and I want to check the rendered output of the specific one. helm template renders all yamls and produces a hundred lines of code. Is there a way (it would be nice to have even a regex) to render only selected template (by a file or eg. a name).

sacherus
  • 1,614
  • 2
  • 20
  • 27

4 Answers4

80

From helm template documentation

-s, --show-only stringArray only show manifests rendered from the given templates

For rendering only one resource use helm template -s templates/deployment.yaml .

edbighead
  • 5,607
  • 5
  • 29
  • 35
  • 8
    One small note. Don't use anything before the "templates" folder. e.g. if you run ```helm template -s ./templates/deployment.yaml .``` it will fails with error ```Error: could not find template ./templates/deployment.yaml in chart``` – V.S. Nov 02 '21 at 13:51
  • @V.S. true, it depends on the actual helm dir structure, starting from the Charts.yml dir – Bennimi Nov 02 '21 at 15:07
  • 1
    Also to note in helm2 the blank template will be rendered as blank but in helm3 it throws the error as `Error: could not find template ./templates/deployment.yaml in chart` , so need to take care when there are if checks in the template . Reference : https://github.com/helm/helm/issues/7295#issuecomment-631151740 – Preetham Nov 18 '21 at 09:31
  • 2
    How do you do this for a subcharts yaml files? – red888 Dec 10 '21 at 19:46
  • @red888 did you manage to do that for a subchart yaml file? I didn't find any way currently – theplayer777 Aug 12 '22 at 07:40
  • 3
    For a subchart with an alias, you use the alias. `helm template . --values=myvalues.yaml --show-only charts/(chart alias)/templates/deployment.yaml`. It's the same path as appears in the `#comment` header when you perform a `helm template` of the entire chart. – Jon O Dec 06 '22 at 03:59
3

If you have multiple charts in one directory:

|helm-charts
|-chart1
|--templates
|---deployment.yaml
|--values.yaml
|--Chart.yaml
|...
|- chart2 

If you want to generate only one file e.g. chart1/deployment.yaml using values from file chart1/values.yaml follow these steps:

  1. Enter to the chart folder:
cd chart1
  1. Run this command:
helm template . --values values.yaml -s templates/deployment.yaml --name-template myReleaseName > chart1-deployment.yaml

Generated manifest will be inside file chart1-deployment.yaml.

R Picheta
  • 630
  • 9
  • 16
3

Rendering individual yaml files using helm template is tricky if chart is inside subdirectory

In case of directory structure as below

|app
|-k8s
|--templates
|---deployment.yaml
|---cronjob.yaml
|--values-env1.yaml
|--values-env2.yaml
|--Chart.yaml

Now for example, if it's required to generate manifest for cronjob.yaml only, the command would be

helm template ./app/k8s -s templates/cronjob.yaml -f ./app/k8s/values-env1.yaml
deepdive
  • 9,720
  • 3
  • 30
  • 38
0

Another solution, is to use yq to filter output, a bit harder but much powefull (you can filter multiple templates):

Example:

helm template . | yq e '. | select(.metadata.name == "*apm*")'
Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124