Skip to main content

Working with Subcharts

1. Adding Subcharts to Chart

Field Description Example
dependencies List of subcharts (dependencies) to include in the main chart [{ name: "nginx", version: "1.2.3", repository: "https://charts.example.com" }]

Example: Adding a subchart to Chart.yaml

apiVersion: v2
name: my-app
version: 1.0.0
dependencies:
  - name: nginx
    version: "1.2.3"
    repository: "https://charts.example.com"
Note: The repository field can be a URL or alias defined in repositories.yaml.
Warning: Helm does not support nested subcharts (subcharts depending on other subcharts). All dependencies must be direct children of the root chart.

2. Declaring Subchart Dependencies

Field Description Example
dependencies List of subchart dependencies [{ name: "nginx", version: "1.2.3", repository: "@stable" }]

Example: Declaring a subchart dependency

dependencies:
  - name: nginx
    version: 1.2.3
    repository: "@stable"
Note: The repository field can be a URL or alias defined in repositories.yaml.

3. Overriding Subchart Values

Property Values Description
subchartName.valueName newValue Override a specific value in a subchart using the dot notation
subchartName.nested.value overriddenValue Override nested values in subcharts

Example: Overriding subchart values in values.yaml

subchart1:
  image:
    tag: "v2.0"
  replicas: 3

subchart2:
  config:
    debug: true
Note: Values overridden in values.yaml take precedence over defaults defined in the subchart's own values.yaml.

4. Using Global Values

Property Description Usage
global.imagePullSecrets Global image pull secrets for all charts global.imagePullSecrets: [{ name: "my-secret" }]
global.storageClass Default storage class for all charts global.storageClass: "fast"
global.namespace Namespace to deploy all charts into global.namespace: "production"

Example: Setting global values in a values.yaml file

global:
  imagePullSecrets:
    - name: my-secret
  storageClass: fast
  namespace: production

myapp:
  replicas: 3

Example: Accessing global values in a template

{{ .Values.global.storageClass }}
{{ .Values.global.namespace }}
Note: Global values are merged into the chart's values during template rendering, allowing for centralized configuration across subcharts.

5. Importing Subchart Values

Property Description Example
importValues Specifies which values from the parent chart are imported into the subchart
[
  {
    "child": "redis",
    "parent": "database"
  }
]

Example: Importing Values from Parent Chart

importValues:
  - child: "redis"
    parent: "database"
Note: The importValues feature is available in Helm v3.10+.

6. Conditionally Enabling Subcharts

Field Description Example
enabled Boolean flag to conditionally enable or disable a subchart true or false
name Name of the subchart to be enabled/disabled nginx-ingress

Example: Enabling subchart based on condition

subchart1:
  enabled: {{ .Values.subchart1.enabled }}
  name: "subchart1"

Example: Using values to control subchart enabling

subchart1:
  enabled: {{ .Values.enableSubchart1 }}
Note: The enabled field in the values file controls whether a subchart is installed. If false, Helm skips installing that subchart even if it's listed in requirements.yaml.
Warning: If a subchart is disabled, its values are not merged into the release, and any dependencies it has will not be resolved.

7. Using Subchart Tags

Tag Description Usage
appVersion Version of the application being deployed "1.2.3"
version Version of the chart itself "1.0.0"
annotations Metadata annotations for the chart {"helm.sh/chart": "my-chart-1.0.0"}

Example: Setting Chart Tags in values.yaml

appVersion: "1.2.3"
version: "1.0.0"
annotations:
  helm.sh/chart: "my-chart-1.0.0"
Note: The appVersion is used to track the version of the application being deployed, while version refers to the chart version.

8. Accessing Parent Values

When a subchart accesses values from its parent chart, it uses the parent keyword in its templates and values files.

Property Description Usage
parent.values Reference to parent chart's values {{ parent.values.key }}

Example: Accessing Parent Values in Subchart Template

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "my-subchart.fullname" . }}
data:
  config.yaml: |
    parentValue: {{ parent.values.someKey }}
Note: The parent.values syntax is only available in Helm 3.10+.

9. Sharing Templates Across Charts

Property Description Usage
_helpers.tpl Template files in this namespace are available to all charts and subcharts Used for shared templates like labels, annotations, or common configurations
include Function to include templates from other charts or subcharts Used in chart templates to render shared components

Example: Using _helpers.tpl

{{- define "mychart.labels" -}}
app: {{ include "mychart.name" . }}
version: {{ include "mychart.version" . }}
{{- end -}}

Example: Including a shared template

metadata:
  labels:
    {{- include "mychart.labels" . | nindent 4 }}

10. Managing Subchart Versions

Field Description Example
version Version of the subchart, used for dependency management 1.2.3
alias Alias to use for the subchart in the parent chart my-subchart
repository Repository URL where the subchart is located https://example.com/charts
condition Condition to enable or disable the subchart subchart.enabled
tags Tags to associate with the subchart for filtering web,api

Example: Defining subchart dependencies

dependencies:
- name: nginx
  version: 1.2.3
  repository: https://kubernetes-charts.storage.googleapis.com/
  condition: nginx.enabled
  tags:
    - web
    - frontend
Note: Helm uses semantic versioning for subchart versions. When updating a subchart, ensure that the new version is compatible with your chart's configuration.
Warning: If a subchart's version is not specified in Chart.yaml, Helm will use the latest available version from the repository, which may introduce breaking changes.

Was this article helpful?