Chart Dependencies
In Helm, one chart may depend on any number of other charts.These dependencies can be dynamically linked through the requirements.yaml
file or brought in to the charts/
directory and managed manually.
Although manually managing your dependencies has a few advantages some teams need,the preferred method of declaring dependencies is by using arequirements.yaml
file inside of your chart.
Note: The dependencies:
section of the Chart.yaml
from HelmClassic has been completely removed.
Managing Dependencies with requirements.yaml
A requirements.yaml
file is a simple file for listing yourdependencies.
dependencies:
- name: apache
version: 1.2.3
repository: http://example.com/charts
- name: mysql
version: 3.2.1
repository: http://another.example.com/charts
- The
name
field is the name of the chart you want. - The
version
field is the version of the chart you want. - The
repository
field is the full URL to the chart repository. Notethat you must also usehelm repo add
to add that repo locally.Once you have a dependencies file, you can runhelm dependency update
and it will use your dependency file to download all the specifiedcharts into yourcharts/
directory for you.
$ helm dep up foochart
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "local" chart repository
...Successfully got an update from the "stable" chart repository
...Successfully got an update from the "example" chart repository
...Successfully got an update from the "another" chart repository
Update Complete.
Saving 2 charts
Downloading apache from repo http://example.com/charts
Downloading mysql from repo http://another.example.com/charts
When helm dependency update
retrieves charts, it will store them aschart archives in the charts/
directory. So for the example above, onewould expect to see the following files in the charts directory:
charts/
apache-1.2.3.tgz
mysql-3.2.1.tgz
Managing charts with requirements.yaml
is a good way to easily keepcharts updated, and also share requirements information throughout ateam.
Alias field in requirements.yaml
In addition to the other fields above, each requirements entry may containthe optional field alias
.
Adding an alias for a dependency chart would puta chart in dependencies using alias as name of new dependency.
One can use alias
in cases where they need to access a chartwith other name(s).
# parentchart/requirements.yaml
dependencies:
- name: subchart
repository: http://localhost:10191
version: 0.1.0
alias: new-subchart-1
- name: subchart
repository: http://localhost:10191
version: 0.1.0
alias: new-subchart-2
- name: subchart
repository: http://localhost:10191
version: 0.1.0
In the above example we will get 3 dependencies in all for parentchart
subchart
new-subchart-1
new-subchart-2
The manual way of achieving this is by copy/pasting the same chart in thecharts/
directory multiple times with different names.
Tags and Condition fields in requirements.yaml
In addition to the other fields above, each requirements entry may containthe optional fields tags
and condition
.
All charts are loaded by default. If tags
or condition
fields are present,they will be evaluated and used to control loading for the chart(s) they are applied to.
Condition - The condition field holds one or more YAML paths (delimited by commas).If this path exists in the parent’s values and resolves to a boolean value,the chart will be enabled or disabled based on that boolean value. Only the firstvalid path found in the list is evaluated and if no paths exist then the conditionhas no effect. For multiple level dependencies the condition is prependend by thepath to the parent chart.
Tags - The tags field is a YAML list of labels to associate with this chart.In the top parent’s values, all charts with tags can be enabled or disabled byspecifying the tag and a boolean value.
# parentchart/requirements.yaml
dependencies:
- name: subchart1
repository: http://localhost:10191
version: 0.1.0
condition: subchart1.enabled
tags:
- front-end
- subchart1
- name: subchart2
repository: http://localhost:10191
version: 0.1.0
condition: subchart2.enabled
tags:
- back-end
- subchart2
# subchart2/requirements.yaml
dependencies:
- name: subsubchart
repository: http://localhost:10191
version: 0.1.0
condition: subsubchart.enabled
# parentchart/values.yaml
subchart1:
enabled: true
subchart2:
subsubchart:
enabled: false
tags:
front-end: false
back-end: true
In the above example all charts with the tag front-end
would be disabled but since thesubchart1.enabled
path evaluates to ‘true’ in the parent’s values, the condition will override thefront-end
tag and subchart1
will be enabled.
Since subchart2
is tagged with back-end
and that tag evaluates to true
, subchart2
will beenabled. Also note that although subchart2
has a condition specified in requirements.yaml
, thereis no corresponding path and value in the parent’s values so that condition has no effect.
subsubchart
is disabled by default but can be enabled by setting subchart2.subsubchart.enabled=true
.Hint: disabling subchart2
via tag will also disable all sub-charts (even if overriding the value subchart2.subsubchart.enabled=true
).
Using the CLI with Tags and Conditions
The —set
parameter can be used as usual to alter tag and condition values.
helm install --set tags.front-end=true --set subchart2.enabled=false
Tags and Condition Resolution
- Conditions (when set in values) always override tags.
- The first condition path that exists wins and subsequent ones for that chart are ignored.
- Tags are evaluated as ‘if any of the chart’s tags are true then enable the chart’.
- Tags and conditions values must be set in the top parent’s values.
- The
tags:
key in values must be a top level key. Globals and nestedtags:
tablesare not currently supported.
Importing Child Values via requirements.yaml
In some cases it is desirable to allow a child chart’s values to propagate to the parent chart and beshared as common defaults. An additional benefit of using the exports
format is that it will enable futuretooling to introspect user-settable values.
The keys containing the values to be imported can be specified in the parent chart’s requirements.yaml
fileusing a YAML list. Each item in the list is a key which is imported from the child chart’s exports
field.
To import values not contained in the exports
key, use the child-parent format.Examples of both formats are described below.
Using the exports format
If a child chart’s values.yaml
file contains an exports
field at the root, its contents may be importeddirectly into the parent’s values by specifying the keys to import as in the example below:
# parent's requirements.yaml file
...
import-values:
- data
# child's values.yaml file
...
exports:
data:
myint: 99
Since we are specifying the key data
in our import list, Helm looks in the exports
field of the childchart for data
key and imports its contents.
The final parent values would contain our exported field:
# parent's values file
...
myint: 99
Please note the parent key data
is not contained in the parent’s final values. If you need to specify theparent key, use the ‘child-parent’ format.
Using the child-parent format
To access values that are not contained in the exports
key of the child chart’s values, you will need tospecify the source key of the values to be imported (child
) and the destination path in the parent chart’svalues (parent
).
The import-values
in the example below instructs Helm to take any values found at child:
path and copy themto the parent’s values at the path specified in parent:
# parent's requirements.yaml file
dependencies:
- name: subchart1
repository: http://localhost:10191
version: 0.1.0
...
import-values:
- child: default.data
parent: myimports
In the above example, values found at default.data
in the subchart1’s values will be importedto the myimports
key in the parent chart’s values as detailed below:
# parent's values.yaml file
myimports:
myint: 0
mybool: false
mystring: "helm rocks!"
# subchart1's values.yaml file
default:
data:
myint: 999
mybool: true
The parent chart’s resulting values would be:
# parent's final values
myimports:
myint: 999
mybool: true
mystring: "helm rocks!"
The parent’s final values now contains the myint
and mybool
fields imported from subchart1.
Managing Dependencies manually via the charts/ directory
If more control over dependencies is desired, these dependencies canbe expressed explicitly by copying the dependency charts into thecharts/
directory.
A dependency can be either a chart archive (foo-1.2.3.tgz
) or anunpacked chart directory. But its name cannot start with _
or .
.Such files are ignored by the chart loader.
For example, if the WordPress chart depends on the Apache chart, theApache chart (of the correct version) is supplied in the WordPresschart’s charts/
directory:
wordpress:
Chart.yaml
requirements.yaml
# ...
charts/
apache/
Chart.yaml
# ...
mysql/
Chart.yaml
# ...
The example above shows how the WordPress chart expresses its dependencyon Apache and MySQL by including those charts inside of its charts/
directory.
TIP:To drop a dependency into your charts/
directory, use thehelm fetch
command
Operational aspects of using dependencies
The above sections explain how to specify chart dependencies, but how does this affectchart installation using helm install
and helm upgrade
?
Suppose that a chart named “A” creates the following Kubernetes objects
- namespace “A-Namespace”
- statefulset “A-StatefulSet”
- service “A-Service”
Furthermore, A is dependent on chart B that creates objects
- namespace “B-Namespace”
- replicaset “B-ReplicaSet”
- service “B-Service”
After installation/upgrade of chart A, a single Helm release is created/modified. The release willcreate/update all of the above Kubernetes objects in the following order:
- A-Namespace
- B-Namespace
- A-StatefulSet
- B-ReplicaSet
- A-Service
- B-Service
This is because when Helm installs/upgrades charts,the Kubernetes objects from the charts and all its dependencies are
- aggregated into a single set; then
- sorted by type followed by name; and then
- created/updated in that order.
Hence a single release is created with all the objects for the chart and its dependencies.
The install order of Kubernetes types is given by the enumeration InstallOrder in kind_sorter.go(see the Helm source file).