Mastering Helm from Scratch: Part 6 - Navigating Chart Dependencies, Libraries, and Repositories
A guide to handling chart dependencies, libraries, and repositories in Helm.
Welcome to Part 6 of Mastering Helm from Scratch! In this chapter, we’ll dive into some of the key features that make Helm charts more versatile and manageable: chart dependencies, chart libraries, and chart repositories. You’ll learn how to create a common library chart and integrate it into your main chart for reusable templates. Additionally, we’ll explore how to create a Helm chart repository, enabling efficient chart sharing and version control across your projects.
Let’s dive into it!
Chart Dependencies
Chart dependencies are external charts that a primary chart needs to function. They allow you to bundle multiple charts together, streamlining installation and management. For example, if your web application chart depends on a database chart, you can define the database as a dependency in your web app’s chart. When you install the web application, Helm will automatically install the required database chart.
For example, you can have an app that depends on the PostgreSQL chart for database functionality. You can specify this dependency in your Chart.yaml
file:
dependencies:
- name: postgres
version: "10.x.x"
repository: "https://charts.bitnami.com/bitnami"
This setup ensures that when you install the app, PostgreSQL is installed automatically.
Then you can use the dependency update command which downloads the necessary dependencies and locks their version:
$ helm dependency update demo-chart
The command also updates the Chart.lock
file, which records the current state of your chart's dependencies. This ensures consistency by locking specific versions of the dependencies, so future installations use the same versions unless manually updated.
Conditions
In Helm, you can control the inclusion of chart dependencies using the condition
field in the Chart.yaml
file. This feature enables you to toggle a dependency on or off based on user-defined values.
The enabled: true
setting within the values.yaml
file determines whether a dependency should be included during the installation. For example, if you want to make the inclusion of a PostgreSQL database optional, you could configure it like this in your Chart.yaml
file:
dependencies:
- name: postgres
version: "10.x.x"
repository: "https://charts.bitnami.com/bitnami"
condition: postgresql.enabled
You can use the enabled
flag in your values.yaml
like this:
postgresql:
enabled: true
Chart Libraries
Chart libraries are collections of reusable templates and functions that can be shared across multiple charts. They help in maintaining consistency and reducing duplication in your Helm charts. For example, you might have a library of common configurations for service deployments that can be utilized in various charts, such as a common-services
library.
To create a chart library, you would follow similar steps as creating a regular chart, but the Chart.yaml
would be structured specifically to indicate that it is a library chart.
Example:
apiVersion: v2
name: mylib
type: library
description: an example library chart
version: 0.1.0
By marking the type
as library
, Helm treats this chart as a collection of templates and functions, which can be imported and used in other charts.
Creating a Library Chart
Keep reading with a 7-day free trial
Subscribe to Curious Devs Corner to keep reading this post and get 7 days of free access to the full post archives.