Sub topic 1
Anatomy of a chart: Chart.yaml, values.yaml and templates/
A Helm chart is a directory of files that Helm turns into Kubernetes manifests. This chapter walks through the layout and the role of each file. Later chapters cover template syntax in detail.
Prerequisites
This chapter assumes you have:
- Basic Kubernetes objects such as Deployment and Service.
- Comfort reading and writing YAML.
- Basic kubectl and command-line use.
- Helm 3 installed locally.
The directory layout
Running helm create webapp scaffolds a chart. The parts that matter most are these:
helm create webapp| Path | Purpose |
|---|---|
| `Chart.yaml` | Metadata about the chart |
| `values.yaml` | Default configuration values |
| `templates/` | Go templates that render into manifests |
| `templates/_helpers.tpl` | Reusable named templates, not rendered as a manifest |
| `charts/` | Packaged subcharts (dependencies) |
| `values.schema.json` | Optional validation rules for values |
Chart.yaml
Chart.yaml identifies the chart. A minimal version looks like this:
apiVersion: v2
name: webapp
description: A small web application
type: application
version: 0.1.0
appVersion: "1.27.0"apiVersion: v2is the chart format used by Helm 3.nameandversionare required. The version follows semantic versioning.typeisapplicationfor a deployable chart, orlibraryfor a chart that only provides helpers.versionis the version of the chart itself. Change it when templates or defaults change.appVersionis the version of the application being deployed. It is informational, but templates often use it as the default image tag.
values.yaml
values.yaml holds the defaults that templates read through .Values. Users override them at install time with -f or --set.
replicaCount: 2
image:
repository: nginx
tag: ""
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
env:
LOG_LEVEL: info
resources: {}Group related settings under a key such as image or service. Nested keys keep overrides readable, for example --set image.tag=1.27.1. An empty tag here signals that the template should fall back to appVersion.
templates/
Every file in templates/ is passed through the Go template engine. Files ending in .yaml or .yml are expected to produce Kubernetes manifests. Files starting with an underscore, such as _helpers.tpl, are loaded for their definitions but do not produce output on their own.
A template mixes plain YAML with actions inside {{ }}:
replicas: {{ .Values.replicaCount }}With the defaults above, this renders as replicas: 2. With --set replicaCount=3, it renders as replicas: 3.
Seeing the result
You can render the chart without a cluster to check the output:
helm lint ./webapp
helm template my-release ./webapp --set replicaCount=3helm lint checks the chart for problems. helm template prints the rendered manifests. Both are covered fully in a later chapter.
Exercise
A chart's Chart.yaml has version: 0.1.0 and appVersion: "1.27.0". You rebuild the container image as 1.27.1 and want the default deployment to use it. Which field or fields do you change, and why would you also change the other one?
Show answer
Change appVersion to "1.27.1", because it describes the deployed application and templates use it as the default image tag when image.tag is empty. Also bump version (for example to 0.1.1), because the chart contents changed and the chart is identified and published by its version.
Exercise
Why does _helpers.tpl start with an underscore?
Show answer
Helm does not render files whose names start with an underscore into Kubernetes manifests. The file is loaded only so its named templates can be reused by other templates.