Skip to main content

Helm Chart Reference

v1.0.0

Template variables, functions, directives, and lifecycle hooks for Helm chart development.

21 entries found

.ValuesVariable

The values passed into the chart via values.yaml, --set flags, or -f overrides. This is the primary source of chart configuration.

image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
.ReleaseVariable

Metadata about the release. Key fields: .Release.Name, .Release.Namespace, .Release.IsInstall, .Release.IsUpgrade, .Release.Revision.

app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
.ChartVariable

Contents of Chart.yaml. Key fields: .Chart.Name, .Chart.Version, .Chart.AppVersion, .Chart.Description.

helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }}
.CapabilitiesVariable

Information about the Kubernetes cluster capabilities. Key: .Capabilities.KubeVersion.Major, .Minor, and .Capabilities.APIVersions.Has.

{{- if .Capabilities.APIVersions.Has "batch/v1/CronJob" }}
apiVersion: batch/v1
{{- end }}
.TemplateVariable

Information about the current template. Key fields: .Template.Name (path), .Template.BasePath.

# Template: {{ .Template.Name }}
includeFunction

Renders a named template and returns the result as a string. Use over template when you need to pipe the result through further functions.

labels:
  {{- include "mychart.labels" . | nindent 4 }}
toYamlFunction

Encodes a value as a YAML string. Commonly used with nindent or indent to render nested structures from Values.

resources:
  {{- toYaml .Values.resources | nindent 2 }}
defaultFunction

Returns the value if set and non-empty; otherwise returns the specified default. Essential for making templates resilient to missing values.

replicas: {{ .Values.replicas | default 1 }}
image: {{ .Values.image.tag | default "latest" }}
requiredFunction

Fails template rendering with a message if a value is empty. Forces callers to provide mandatory values.

host: {{ required "A hostname is required" .Values.ingress.host }}
quoteFunction

Wraps a string value in double quotes. Ensures YAML strings containing special characters are properly quoted.

env:
  - name: LOG_LEVEL
    value: {{ .Values.logLevel | quote }}
nindentFunction

Like indent but prepends a newline. Pair with toYaml for clean multi-line block rendering.

spec:
  template:
    spec:
      containers:
        {{- toYaml .Values.extraContainers | nindent 8 }}
tplFunction

Renders a string as a Helm template. Allows values.yaml entries to contain template expressions.

{{- tpl .Values.configTemplate . }}
lookupFunction

Queries the Kubernetes API during rendering. Returns a resource object or empty dict if not found.

{{- $secret := lookup "v1" "Secret" .Release.Namespace "my-secret" }}
{{- if $secret }}existing{{ end }}
rangeDirective

Iterates over a list or map. Sets . to the current item (list) or provides key/value variables (map).

{{- range .Values.ports }}
- containerPort: {{ . }}
{{- end }}
withDirective

Changes the scope of . to the given value. Skips the block if the value is empty — useful for optional config sections.

{{- with .Values.nodeSelector }}
nodeSelector:
  {{- toYaml . | nindent 2 }}
{{- end }}
define / include (named templates)Directive

define creates a named template block (usually in _helpers.tpl). include renders it; template renders without returning a value.

{{- define "mychart.labels" -}}
app: {{ .Chart.Name }}
release: {{ .Release.Name }}
{{- end }}
pre-installHook

Runs before any resources are installed. Useful for schema migrations, secret seeding, or prerequisites.

annotations:
  "helm.sh/hook": pre-install
  "helm.sh/hook-weight": "-5"
  "helm.sh/hook-delete-policy": hook-succeeded
post-installHook

Runs after all installation resources are created. Commonly used for smoke tests or post-setup config.

annotations:
  "helm.sh/hook": post-install
  "helm.sh/hook-delete-policy": before-hook-creation
pre-upgradeHook

Runs before an upgrade is applied. Suitable for draining jobs, backup tasks, or locking checks.

annotations:
  "helm.sh/hook": pre-upgrade
post-upgradeHook

Runs after a successful upgrade. Use for cache warming, notification sending, or validation.

annotations:
  "helm.sh/hook": post-upgrade
  "helm.sh/hook-delete-policy": hook-succeeded
helm.sh/hook: testHook

Marks a Pod manifest as a Helm test. Run with helm test <RELEASE>. Pod must exit 0 for the test to pass.

annotations:
  "helm.sh/hook": test
spec:
  containers:
    - name: test-conn
      image: busybox
      command: ['wget', 'http://{{ .Release.Name }}-svc']