Chart Anatomy
A Helm chart is a directory (or a .tgz of that directory) with a fixed layout. Helm reads a handful of well-known files and renders everything under templates/. Knowing which file does what is most of the battle when you open someone else's chart.
The layout
linkly/
├── Chart.yaml # required: name, version and metadata
├── values.yaml # default values for the templates
├── values.schema.json # optional: JSON Schema the values must satisfy
├── .helmignore # files to leave out of the package (like .gitignore)
├── charts/ # dependencies (subcharts), as directories or .tgz files
├── crds/ # optional: CustomResourceDefinitions, installed before templates, never templated
├── templates/
│ ├── _helpers.tpl # files starting with "_" hold named templates and render no output
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── NOTES.txt # rendered and printed after install/upgrade
│ └── tests/ # test pods run by `helm test`
├── README.md
└── LICENSEOnly Chart.yaml is strictly required, though a chart without templates does nothing. helm create writes a starter with all the usual pieces; this course mostly builds charts by hand so that every line is one you understand.
Chart.yaml
mkdir -p linkly/templates && cd linkly
cat > Chart.yaml <<'EOF'
apiVersion: v2
name: linkly
description: A link shortener (Go, PostgreSQL, Redis)
type: application
version: 0.1.0
appVersion: "1.4.0"
kubeVersion: ">= 1.30.0-0"
home: https://github.com/acme/linkly
sources: [https://github.com/acme/linkly]
maintainers:
- name: Platform Team
email: platform@example.com
keywords: [url-shortener, go]
annotations:
category: Networking
EOF
cat > values.yaml <<'EOF'
replicaCount: 2
EOF
cat > templates/configmap.yaml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-config
data:
replicas: "{{ .Values.replicaCount }}"
EOF
helm show chart .
helm lint .
helm template demo .annotations:
category: Networking
apiVersion: v2
appVersion: 1.4.0
description: A link shortener (Go, PostgreSQL, Redis)
home: https://github.com/acme/linkly
keywords:
- url-shortener
- go
kubeVersion: '>= 1.30.0-0'
maintainers:
- email: platform@example.com
name: Platform Team
name: linkly
sources:
- https://github.com/acme/linkly
type: application
version: 0.1.0
==> Linting .
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed
---
# Source: linkly/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: demo-config
data:
replicas: "2"
What each field means:
| Field | Meaning |
|---|---|
apiVersion |
the chart format: v2 for Helm 3 and 4 charts (v1 was Helm 2; v3 is experimental in Helm 4, behind HELM_EXPERIMENTAL_CHART_V3) |
name |
the chart's name; must match the directory name when you package it |
version |
the chart's SemVer version. Bump it whenever anything in the chart changes |
appVersion |
the version of the application the chart deploys, free-form text; quote it so YAML doesn't turn 1.10 into 1.1 |
type |
application (renders objects) or library (only provides named templates to other charts) |
kubeVersion |
a SemVer constraint on the cluster version; Helm refuses to render or install outside it |
dependencies |
subcharts, see Chart Dependencies |
home, sources, maintainers, keywords, icon, annotations |
metadata shown by helm show chart and chart portals such as Artifact Hub |
deprecated |
true marks the chart as deprecated in repositories |
helm lint passed with one [INFO]: an icon URL is "recommended", not required. INFO lines never fail a lint, WARNINGs fail it only with --strict, and ERRORs always fail.
kubeVersion in action
The -0 suffix is the form the Helm documentation recommends. Managed clusters report versions such as 1.34.2-eks-1234, which strict SemVer treats as a pre-release of 1.34.2, and in many SemVer libraries a constraint without a pre-release part (>= 1.30.0) excludes pre-releases. Helm 4.3 happens to be lenient here, but the suffix costs nothing and keeps the constraint correct for every tool that reads it. helm template assumes a default Kubernetes version (the one Helm was built against) unless you pass --kube-version, so you can test the constraint offline:
mkdir -p linkly/templates && cd linkly
printf 'apiVersion: v2\nname: linkly\nversion: 0.1.0\nkubeVersion: ">= 1.30.0-0"\n' > Chart.yaml
printf 'apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: x\n' > templates/cm.yaml
helm template demo . --kube-version 1.34.2-eks-1234 | grep kind
helm template demo . --kube-version 1.29.9
echo "exit code: $?"kind: ConfigMap
Error: chart requires kubeVersion: >= 1.30.0-0 which is incompatible with Kubernetes v1.29.9
Use --debug flag to render out invalid YAML
exit code: 1
.helmignore and the package
helm package builds the .tgz you publish, and .helmignore keeps junk out of it. Patterns work like .gitignore:
mkdir -p linkly/templates linkly/ci && cd linkly
printf 'apiVersion: v2\nname: linkly\nversion: 0.1.0\n' > Chart.yaml
printf 'replicaCount: 2\n' > values.yaml
printf 'apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: x\n' > templates/cm.yaml
echo "lint: helm lint ." > ci/Makefile
echo "notes" > TODO.md
printf 'ci/\n*.md\n.git/\n' > .helmignore
cd .. && helm package linkly >/dev/null
tar -tzf linkly-0.1.0.tgz | sortlinkly/.helmignore
linkly/Chart.yaml
linkly/templates/cm.yaml
linkly/values.yaml
Inside the archive everything sits under a top-level linkly/ directory, which is why the chart's name must match its directory. .helmignore itself is packaged so the rules travel with the chart.
Library charts
A type: library chart contains only _*.tpl files with named templates. Other charts list it as a dependency and include its templates, which is how organisations share one definition of "standard labels" or "a hardened container spec" across dozens of charts. A library chart cannot be installed on its own. Helpers & Named Templates shows the templates it would contain.
Test yourself
You change a template but not the application. What should change in Chart.yaml?
- appVersion
- version
- apiVersion
- Nothing
Why write kubeVersion: ">= 1.30.0-0" rather than ">= 1.30.0"?
- It is shorter
- So that provider versions like 1.34.2-eks-1234 (SemVer pre-releases) satisfy the constraint under strict SemVer rules
- To allow Kubernetes 0.x
- Helm requires the suffix
What is special about templates/_helpers.tpl?
- It is rendered first and printed
- Files starting with an underscore render no manifests; they hold named templates
- It is ignored entirely
- It must contain the Deployment