Helm Templates: Difference between revisions
(→Values) |
(→Values) |
||
Line 65: | Line 65: | ||
... | ... | ||
data: | data: | ||
size: | size: {{ .Values.size }} | ||
===Release=== | ===Release=== |
Revision as of 03:30, 29 August 2019
External
- The Chart Template Developer’s Guide https://helm.sh/docs/chart_template_guide/#the-chart-template-developer-s-guide
Internal
Overview
Templates are files living under a chart's templates/ directory. They are written in YAML with Helm templates extensions. Upon processing by Helm, they become Kubernetes manifest files. Helm template extensions are written in the Help template language, which is based on Go templates.
The templates/ Directory
The 'templates' directory contains templates that, after combination with values, will the Kubernetes manifests. When Tiller evaluates a chart, it will send all of the files in the directory through the template rendering engine, then collect the results and send them to to Kubernetes.
Template names do not follow a rigid naming pattern. It is, however, recommended to use the suffix .yaml for YAML files and .tpl for helpers.
It also contains the following files:
Files whose names start with "_" or "." will be ignored. - Really? helm install complained about _pod.yaml.
Template Directives
A template directive is enclosed in {{ and }} blocks, and it is recommended to pad the directive with space at its left and right.
Simple Replacement
The simplest directive is a value, which is a namespaced object, where each dot (.) separates each namespaced element. A leading dot indicates that we start with the top-most namespace for the scope.
kind: ConfigMap metadata: name: {{ .Release.Name }}-configmap
Scopes
Template Objects
Objects are passed into a template from the template engine. The template directives can create new objects and pass them around. There are also built-in objects, which are made available by default.
Objects can be simple - have just one value -, or they can contain other objects or functions. For example the "Release" built-in object contains several other objects (like "Release.Name"). The "Files" object contains functions.
Built-in Objects
Chart
Exposes all contents of Chart.yaml. An existing field is available as (note leading dot) .Chart.<UpperCasedFirstLetterFieldName>.
Example:
{{ .Chart.Name }} {{ .Chart.Version }}
Values
This object contains values passed into template from the values.yaml file and from user-supplied files. For example, a value declared as such in values.yaml:
size: 10
can be references in a template as such:
kind: ConfigMap ... data: size: {{ .Values.size }}
Release
This object describes the release itself.
Release.Name
Exposes the release name:
{{ .Release.Name }}
Release.Revision
Exposes the release revision:
{{ .Release.Revision }}
Release.Time
Exposes the time of the release:
{{ .Release.Time }}
Release.Namespace
Exposes the namespace to be released info, if the manifest does not override:
{{ .Release.Namespace }}
Release.IsUpgrade
This is set to true if the current operation is an upgrade or rollback.
{{ .Release.IsUpgrade }}
Release.IsInstall
This is set to true if the current operation is an install.
{{ .Release.IsInstall }}
Release.Service
Exposes the releasing service - always Tiller
Files
Capabilities
Template
TODO
Template Comments
# This is a comment
{{- /* This is another comment */ -}}
TODO
- https://helm.sh/docs/chart_template_guide/#the-chart-template-developer-s-guide
- https://helm.sh/docs/chart_best_practices/#templates
- https://helm.sh/docs/developing_charts/#templates-and-values
- https://helm.sh/docs/developing_charts/#know-your-template-functions
- https://helm.sh/docs/developing_charts/#quote-strings-don-t-quote-integers
- https://helm.sh/docs/developing_charts/#using-the-include-function
- https://helm.sh/docs/developing_charts/#using-the-required-function
- https://helm.sh/docs/developing_charts/#using-the-tpl-function
- https://helm.sh/docs/developing_charts/#creating-image-pull-secrets
- https://helm.sh/docs/developing_charts/#automatically-roll-deployments-when-configmaps-or-secrets-change
- https://helm.sh/docs/developing_charts/#tell-tiller-not-to-delete-a-resource
- https://helm.sh/docs/developing_charts/#using-partials-and-template-includes
- https://helm.sh/docs/chart_best_practices/#pods-and-podtemplates
- https://helm.sh/docs/chart_best_practices/#images
- https://helm.sh/docs/chart_best_practices/#imagepullpolicy
- https://helm.sh/docs/chart_best_practices/#podtemplates-should-declare-selectors