Sub topic 2
Anatomy of a chart
Prerequisites
This chapter assumes you know basic Kubernetes objects (Pods, Deployments, Services, ConfigMaps), can read YAML, and can run kubectl and helm from a terminal. You do not need to write templates yet. Later chapters cover that.
What a chart is on disk
A chart is a directory with a fixed layout. Helm reads that layout to know which files are metadata, which are defaults, and which are Kubernetes manifests to render. Running helm create webapp generates a working starter chart.
helm create webappThe most important parts look like this:
webapp/
Chart.yaml
values.yaml
values.schema.json
charts/
templates/
deployment.yaml
service.yaml
_helpers.tpl
NOTES.txt
tests/| Path | Purpose |
|---|---|
| `Chart.yaml` | Chart name, versions, and metadata. Required. |
| `values.yaml` | Default configuration values. |
| `values.schema.json` | Optional JSON schema that validates values. |
| `charts/` | Subcharts that this chart depends on. |
| `templates/` | Manifest templates that Helm renders. |
| `templates/_helpers.tpl` | Named template definitions. It produces no manifest itself. |
| `templates/NOTES.txt` | Text shown to the user after install. |
Files in templates/ whose names start with an underscore are never rendered as manifests. They exist to hold reusable snippets.
Chart.yaml
Chart.yaml identifies the chart. A minimal one looks like this:
apiVersion: v2
name: webapp
description: A simple web application
type: application
version: 0.1.0
appVersion: "1.27"The fields you will use most:
apiVersion: v2is the chart format for Helm 3 and later.nameis the chart name. It should match the directory name.typeisapplication(installable) orlibrary(only provides helpers to other charts).versionis the version of the chart itself. It follows semantic versioning.appVersionis the version of the application the chart deploys. It is informational unless your templates use it.
Two version numbers
The most common confusion is the difference between version and appVersion. They change independently.
- Change
versionwhenever anything in the chart changes, such as a template fix or a new value. Helm uses it to identify a packaged chart. - Change
appVersionwhen the deployed application changes, for example from nginx 1.27 to 1.28.
A chart can go from 0.1.0 to 0.1.1 with the same appVersion. Quote appVersion. Unquoted, YAML parses 1.27 as a number, and a value like 1.20 would lose its trailing zero.
How the pieces fit together
Helm combines the files when you install or render a chart. Defaults from values.yaml and any overrides become the .Values object. The metadata in Chart.yaml becomes .Chart. Templates read both and produce plain Kubernetes YAML.
Inspecting a chart
Before you read any template, check that the chart is well formed. helm lint checks the structure and Chart.yaml. helm template renders the manifests locally without contacting the cluster.
helm lint ./webapp
helm template my-release ./webappIf helm lint reports a missing name or an invalid version, fix Chart.yaml first. Later errors often come from a malformed header.
Common errors
- The directory name differs from
name. Helm warns during lint, and packaging produces a confusing archive name. Keep them equal. - A non-semver
version. Values like1orv1.0are rejected or misordered. Use1.0.0. - Files placed outside
templates/. Helm ignores manifests in the chart root. Only files undertemplates/are rendered. - Expecting
appVersionto set the image tag automatically. It does nothing by itself. A template must read.Chart.AppVersion, as you will see in the templates chapter.
Exercise
A team fixes a typo in a chart's service template but does not change the nginx image. Which field in Chart.yaml should change, version or appVersion, and why?
Show answer
Change version. The chart itself changed, so it needs a new chart version (for example 0.1.0 to 0.1.1). appVersion describes the deployed application, and the application did not change.
Exercise
You add a file named _labels.tpl to templates/ that contains only a define block. Will Helm try to create a Kubernetes object from it?
Show answer
No. Files in templates/ whose names start with an underscore are not rendered as manifests. They are used to hold named templates that other templates include.