Built-in Objects
Helm exposes objects like .Values, .Release, .Chart, and .Capabilities that templates can read.
Syntax
{{ .Release.Name }}
{{ .Chart.Version }}Beyond your own values, Helm injects several built-in objects into every template. They all hang off the root context (the dot).
The main objects
.Values— the merged values (from values.yaml,-ffiles, and--set)..Release— data about this release:.Release.Name,.Release.Namespace,.Release.Revision,.Release.IsUpgrade,.Release.IsInstall..Chart— fields from Chart.yaml:.Chart.Name,.Chart.Version,.Chart.AppVersion..Capabilities— what the target cluster supports, e.g..Capabilities.KubeVersion..Files— access to non-template files in the chart..Template— info about the current template being rendered.
Example
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}
namespace: {{ .Release.Namespace }}
labels:
chart-version: {{ .Chart.Version }}
app-version: {{ .Chart.AppVersion }}
revision: "{{ .Release.Revision }}"When to use it
- A chart author uses {{ .Release.Name }} to prefix every resource name so multiple releases of the same chart can coexist in the same namespace without name collisions.
- A template uses {{ .Chart.AppVersion }} to embed the application version in a Pod label, making it easy to filter Pods by version in kubectl or Datadog.
- A developer checks {{ .Capabilities.KubeVersion.Minor }} to render different apiVersion fields for PodDisruptionBudget depending on whether the cluster supports the newer policy/v1 API.
More examples
Use Release and Chart objects
Uses built-in .Release and .Chart objects to generate unique names and standard labels without hardcoding values.
# templates/deployment.yaml
metadata:
name: {{ .Release.Name }}-app
namespace: {{ .Release.Namespace }}
labels:
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}Capabilities version check
Selects the correct PodDisruptionBudget apiVersion based on the cluster's Kubernetes version using .Capabilities.
{{- if semverCompare ">=1.21-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: policy/v1
{{- else }}
apiVersion: policy/v1beta1
{{- end }}
kind: PodDisruptionBudgetFiles object for config data
Reads a static file from the chart directory using the .Files built-in object and embeds its content in a ConfigMap.
# templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-config
data:
app.conf: |
{{- .Files.Get "files/app.conf" | nindent 4 }}
Discussion