Helm
Structure
Useful commands
helm install full-coral ./mychart
helm install RELEASE_NAME PATH_TO_CHART
helm get manifest full-coral
helm uninstall full-coral
helm install --debug --dry-run full-coral ./mychart
helm dependencies build; helm template ./ -f values.yaml
you can not create template of particular yaml file, only all
Built-in objects
Release
{{ .Release.Name }}
Values
Chart
Files
Capabilities
Template
Values files
The
values.yaml
file in the chartIf this is a subchart, the
values.yaml
file of a parent chartA values file if passed into
helm install
orhelm upgrade
with the-f
flag (helm install -f myvals.yaml ./mychart
)Individual parameters passed with
--set
(such ashelm install --set foo=bar ./mychart
)
Function
functionName arg1 arg2...
For example
Pipeline
Passing a value through 1..N functions (.Values.favorite.food | upper | quote)
Useful function default
default
drink: {{ .Values.favorite.drink | default "tea" | quote }}
the
default
command is perfect for computed values, which cannot be declared insidevalues.yaml
Useful function lookup
The lookup
function can be used to look up resources in a running cluster. The synopsis of the lookup function is lookup apiVersion, kind, namespace, name -> resource or resource list
.
Behavior | Lookup function |
---|---|
|
|
|
|
|
|
|
|
|
|
Flow control
Helm's template language provides the following control structures:
if
/else
for creating conditional blocks
if
/else
for creating conditional blocksA pipeline is evaluated as false if the value is:
a boolean false
a numeric zero
an empty string
a
nil
(empty or null)an empty collection (
map
,slice
,tuple
,dict
,array
)
Whitespaces may be tricky while rendering a temple
you may sometimes find it useful to use the indent
function ({{ indent 2 "mug:true" }}
)
with
to specify a scope
with
to specify a scopeNotice that now we can reference .drink
and .food
without qualifying them. That is because the with
statement sets .
to point to .Values.favorite
. The .
is reset to its previous scope after {{ end }}
.
But here's a note of caution! Inside of the restricted scope, you will not be able to access the other objects from the parent scope using .
. This, for example, will fail:
range
, which provides a "for each"-style loop
Named templates
An important detail to keep in mind when naming templates: template names are global. If you declare two templates with the same name, whichever one is loaded last will be the one used. Because templates in subcharts are compiled together with top-level templates, you should be careful to name your templates with chart-specific names.
These files are used to store partials and helpers. In fact, when we first created mychart
, we saw a file called _helpers.tpl
. That file is the default location for template partials.
define
declares a new named template inside of your templatetemplate
imports a named template
Conventionally, Helm charts put these templates inside of a partials file, usually _helpers.tpl
. Let's move this function there:
block
declares a special kind of fillable template area
Variables
Debugging Templates
Debugging templates can be tricky because the rendered templates are sent to the Kubernetes API server, which may reject the YAML files for reasons other than formatting.
There are a few commands that can help you debug.
helm lint
is your go-to tool for verifying that your chart follows best practiceshelm template --debug
will test rendering chart templates locally.helm install --dry-run --debug
: We've seen this trick already. It's a great way to have the server render your templates, then return the resulting manifest file.helm get manifest
: This is a good way to see what templates are installed on the server.
When your YAML is failing to parse, but you want to see what is generated, one easy way to retrieve the YAML is to comment out the problem section in the template, and then re-run helm install --dry-run --debug
:
The above will be rendered and returned with the comments intact:
This provides a quick way of viewing the generated content without YAML parse errors blocking.
Last updated