Dependencies
In this chapter we’ll look at bundling charts together with subcharts and dependencies. This allows us to create a single release bundling all applications (frontend, backend and the database).
Exercise - Deploying the application in separate releases
In the last section we looked at how we can create a Helm chart from scratch to deploy our database. Now we are going to deploy the remaining components todobackend and todoui as well. Fortunately there are already helm charts prepared so we don’t have to create those now. When you look at those charts with
tree todobackend/helmchart/
and
tree todoui/helmchart
you will see that they are pretty similar to the one we just created.
We can now deploy the whole application with three helm installs:
helm install postgres ./postgresdb/helmchart
helm install todobackend ./todobackend/helmchart
helm install todoui ./todoui/helmchart
This works well and may just be enough for our simple scenario but you can probably imagine how tedious this would get if you had more than just three components to your application.
Luckily Helm comes with the capability of bundling multiple charts into a single release by using dependencies. But before we dive into the next section we should clean up again:
helm uninstall postgres todobackend todoui
Subcharts vs Dependencies
Helm offers two ways of organizing the dependencies of a chart:
- Dependencies in Chart.yaml
- Subcharts
In this section we’re going to walk you through both of these options.
Exercise - Creating the parent chart
Let’s start by creating a new chart which we are going to use as our parent.
- Create the parentchart with
helm create parentchartwhile you are in the root directory of the exercises. - Clean the templates directory by running
rm -r parentchart/templates/*. - Delete all contents of values.yaml
- Verify your helmchart by running
tree parentchart. It should look like this:
parentchart
├── charts
├── Chart.yaml
├── templates
└── values.yaml
2 directories, 2 filesExercise - Adding the three dependencies to Chart.yaml
We can simply specify dependencies in Chart.yaml by using the dependencies: property. Open Chart.yaml in a
text editor and insert the following code at the bottom of the file:
dependencies:
- name: postgresdb
version: "0.1.0"
repository: file://../postgresdb/helmchart/
- name: todobackend
version: "0.1.0"
repository: file://../todobackend/helmchart/
- name: todoui
version: "0.1.0"
repository: file://../todoui/helmchart/Before we can install the parentchart we need to do one more thing. The command helm dependency update parentchart/
will load the dependencies into the parents charts/ directory so they can be deployed when you run helm install.
Exercise - Installing the parent chart
Try running helm install todo ./parentchart/ now and you should see the whole application being deployed!
Note
You may have noticed that the charts in the charts/ directory are .tgz files. Helm uses packaging to reduce the size
of charts. They can still be installed with helm install todobackend-0.1.0.tgz and you can manually package charts
with the helm package <chart directory> command.
Exercise - Parentchart cleanup
Before we start the next exercise please run the following commands to clean up:
helm uninstall todo to uninstall the helm release
rm parentchart/charts/* to remove the dependencies charts
nano parentchart/Chart.yaml to remove the dependency declarations
Chart.yaml should look like this:
apiVersion: v2
name: parentchart
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.16.0Exercise - Subcharts
The second option for bundling helm charts would be subcharts. It’s the same principle as listing dependencies in Chart.yaml but we’re simply skipping the step of declaring the dependencies in the chart file by directly placing them as subcharts in the parents charts/ directory.
As a consequence our subcharts can inject values from the parent or override them.
All we have to do to turn our standalone charts into subcharts, is copy them in the parents charts/ directory with the following commands:
cp -r postgresdb/helmchart parentchart/charts/postgresdb
cp -r todobackend/helmchart parentchart/charts/todobackend
cp -r todoui/helmchart parentchart/charts/todoui
Running tree parentchart/ should output
parentchart
├── charts
│ ├── postgresdb
│ │ ├── charts
│ │ ├── Chart.yaml
│ │ ├── templates
│ │ │ ├── postgres-service.yaml
│ │ │ └── postgres.yaml
│ │ └── values.yaml
│ ├── todobackend
│ │ ├── charts
│ │ ├── Chart.yaml
│ │ ├── templates
│ │ │ ├── todobackend-service.yaml
│ │ │ └── todobackend.yaml
│ │ └── values.yaml
│ └── todoui
│ ├── charts
│ ├── Chart.yaml
│ ├── templates
│ │ ├── todoui-service.yaml
│ │ └── todoui.yaml
│ └── values.yaml
├── Chart.yaml
├── templates
└── values.yamlExercise - Installing the parentchart with subcharts
After we put the subcharts in the right directory all that’s left to do is installing the parentchart again. Run
helm install todo ./parentchart/
again and see what’s happening now!
Exercise - Subchart cleanup
To clean up, please run helm uninstall todo once more.
Summary
In this chapter we learned how we can bundle and deploy multiple helmcharts in one release using either dependency declarations or subcharts. These two approaches practically accomplish the same thing, yet there is still a point to be made for preferring dependencies over subcharts.
Placing the tarballs of dependencies directly into the parent chart’s directory structure forces you to manually update those once your dependencies receive a version bump.
Declaring a subchart as a dependency allows you to separately version it. It will have its own repository with its own, independent version history that your parent chart can choose from.