Sub topic 3
Packaging a Chart into a .tgz Archive
This chapter assumes you can install a chart, read Chart.yaml and values.yaml, and have Helm 3.8 or later installed. Before a chart can go to an OCI registry, you package it into a single .tgz file. That file is what helm push uploads.
What helm package produces
A chart in development is a directory of templates, values, and metadata. helm package compresses that directory into a gzip-compressed tar archive. The archive name comes from two fields in Chart.yaml: name and version.
apiVersion: v2
name: myapp
description: Example application chart
type: application
version: 0.1.0
appVersion: "1.0.0"With this file, the archive is named myapp-0.1.0.tgz. Later chapters show that the same two fields also set the repository path and the tag in the registry, so it pays to get them right now.
helm package ./myapp
# Successfully packaged chart and saved it to: /path/to/myapp-0.1.0.tgzThe command writes the archive to the current directory unless you pass --destination.
The two version fields
Chart.yaml has two version fields that people often confuse.
| Field | Meaning | Used for |
|---|---|---|
| `version` | Version of the chart itself | Archive file name, registry tag |
| `appVersion` | Version of the application the chart deploys | Information only |
The version field must be valid Semantic Versioning 2 (for example 0.1.0 or 1.2.3-rc.1). If you change a template, bump version. If you only change the application image, you may bump appVersion too, but the chart version still identifies the package.
What happens during packaging
Helm reads Chart.yaml, checks that the chart is well formed, and bundles everything in the directory except files listed in .helmignore. If the chart declares dependencies, the charts/ directory must contain them, or packaging with --dependency-update fetches them first.
Useful flags
--destination distwrites the archive todist/. The directory must already exist.--version 0.2.0overrides the chart version for this run, without editingChart.yaml.--app-version 1.1.0overridesappVersionthe same way.--dependency-update(or-u) runs a dependency update before packaging.--signcreates a provenance file. This is covered in a later chapter.
The overrides are handy in CI, where the version can come from a Git tag:
mkdir -p dist
helm package ./myapp --version 0.2.0 --app-version 1.1.0 --destination dist
ls dist
# myapp-0.2.0.tgzInspect before you push
Check what you built before it goes to a registry. A pushed tag is hard to take back cleanly, and many registries let teams make tags immutable.
helm lint ./myapp
tar -tzf dist/myapp-0.2.0.tgzhelm lint catches template and metadata problems. tar -tzf lists the archive contents. Every path starts with the chart name, such as myapp/Chart.yaml. If you see files that should not ship, such as local test values or secrets, add patterns to .helmignore and package again.
Common errors
- Directory name differs from chart name. Older Helm releases complained when the folder name did not match
nameinChart.yaml. Keep them identical to avoid confusion. - Invalid version. A value like
1.0orv1is rejected or misread. Use three numeric parts. - Missing dependencies. Packaging fails if
Chart.yamllists dependencies that are not incharts/. Runhelm dependency updateor add--dependency-update. - Stale archives.
helm packageoverwrites an existing file with the same name. Old archives in a shared directory can be pushed by mistake when you use a wildcard such as*.tgz. Package into a clean directory.
Exercise
You run helm package ./myapp --version 2.0.0 --destination dist on a chart whose Chart.yaml says version: 0.1.0. What is the archive file name, and does Chart.yaml change?
Show answer
The archive is dist/myapp-2.0.0.tgz. The --version flag overrides the version only for this packaging run, so Chart.yaml still says 0.1.0. The dist directory must exist beforehand.
Exercise
How can you check which files ended up inside myapp-0.2.0.tgz without extracting it, and how do you keep a local secrets.yaml out of the archive?
Show answer
Run tar -tzf myapp-0.2.0.tgz to list the contents. To exclude the file, add secrets.yaml to .helmignore in the chart directory and package again.