Sub topic 2
Declaring dependencies in Chart.yaml
This chapter assumes you know Helm 3 basics (install, upgrade, release), the chart layout, and how values.yaml works. It covers how a chart declares the charts it needs. The next chapter covers downloading and locking them.
Why declare dependencies
A chart often needs other software, such as a cache, a database, or a shared set of template helpers. Instead of copying those manifests into your templates, you declare the other chart as a dependency. Helm calls a chart that another chart depends on a subchart. The chart that declares the dependency is the parent chart.
The parent and its subcharts are installed together as one release. Helm renders all their templates and applies them in a single operation.
The dependencies field
For charts with apiVersion: v2, dependencies live in the dependencies list in Chart.yaml. Charts with apiVersion: v1 used a separate requirements.yaml file. New charts should use v2.
apiVersion: v2
name: webapp
description: Example web application chart
type: application
version: 0.1.0
appVersion: "1.0.0"
dependencies:
- name: cache
version: "~1.2.0"
repository: https://charts.example.com/stable
condition: cache.enabled
tags:
- backend
- name: common-helpers
version: 0.1.0
repository: file://../common-helpersEach entry describes one subchart. The table lists the fields.
| Field | Required | Meaning |
|---|---|---|
| `name` | Yes | The subchart's name. It must match the `name` in the subchart's own `Chart.yaml`. |
| `version` | Yes | An exact version or a semantic version range. |
| `repository` | No | Where to fetch the chart: an `https://` URL, an `oci://` URL, a `file://` path, or an `@alias` for a repository you added locally. |
| `condition` | No | A values path that turns the dependency on or off. |
| `tags` | No | Labels that let you switch groups of dependencies together. |
| `alias` | No | A different name to use for this dependency in values and templates. |
| `import-values` | No | Pulls selected values from the subchart up into the parent. |
This chapter covers name, version, and repository. The other fields appear in later chapters, but you can see condition and tags in the example above.
Version constraints
The version field accepts semantic version ranges. Helm picks the newest available chart that satisfies the range.
1.2.3matches exactly that version.~1.2.0means>=1.2.0 <1.3.0. Patch updates are allowed.^1.2.0means>=1.2.0 <2.0.0. Minor and patch updates are allowed.>=1.2.0 <2.0.0is an explicit range.
Ranges keep your chart open to fixes, but two people who run an update on different days can get different versions. That is why Helm writes a Chart.lock file. It pins the exact versions that were resolved.
Choosing a repository
The repository value decides how Helm finds the chart.
- An
https://URL points to a classic chart repository. - An
oci://URL points to a chart stored in an OCI registry. - A
file://path points to a chart directory on disk. The path is relative to the parent chart's directory, sofile://../common-helpersis a sibling directory. This is useful in a monorepo or while you develop a subchart and its parent together. - An empty or omitted
repositorymeans the subchart is already inside the parent'scharts/directory, and Helm does not fetch it.
For a local file:// dependency, the version you declare must be satisfied by the version in that directory's Chart.yaml. Here the local chart must have version: 0.1.0.
Common errors
- Name mismatch. If
namediffers from the chart's real name, the fetch fails. For a repository, the name must exist in the repository index. Forfile://, it must match the directory'sChart.yaml. - Unknown repository. For a plain
https://URL, Helm expects the repository to be known locally. Runhelm repo addfirst, or you get a "no repository definition" error. OCI references do not need this step. - No matching version. A constraint such as
~1.2.0fails if the repository only has1.3.x. Check the available versions withhelm search repo. - Wrong file name. Putting dependencies in
requirements.yamlin a v2 chart is a legacy pattern. Keep everything inChart.yaml.
Exercise
Your parent chart sits in ./shop, and a shared chart named labels sits in ./labels with version 2.0.1. Write the dependencies entry that declares it, and say which version values would work.
Show answer
The entry is - name: labels, version: 2.0.1, repository: file://../labels. The path is relative to the parent chart directory ./shop, so ../labels reaches the sibling directory. A version of 2.0.1, ~2.0.0, or ^2.0.0 would all match the local chart's version.