Creating A Helm Chart Template: A Step by Step Guide

Table of contents

Creating a Template for a Helm Chart: A Step-by-Step Guide

Helm, also known as the "Kubernetes package manager," is an open-source project that streamlines the process of defining, installing, and upgrading even the most complex Kubernetes applications. One of the most useful features of Helm is the ability to create templates for Kubernetes resources, enabling consistent, and simple quality deployments. This Helm Chart Template Tutorial will guide you through the process of creating a Helm template from scratch.

What you Need to Create Helm Chart Templates

Before we start, make sure you have:

- Helm installed on your system
- A Kubernetes cluster where you can test deploy your Helm chart
- Basic understanding of Kubernetes resources and Helm charts (For more info, head here) 

Step 1: Creating a New Helm Chart

To create a new Helm chart, use the `helm create` command followed by the name of your chart. For example, to create a chart named `mychart`, run the following command:

This command creates a new directory named, `mychart`

Step 2: Understanding the Chart Structure

Before modifying your chart, it's important to understand the structure of the newly created directory. To help, here is the basic outline of a directory structure: 

- `Chart.yaml`: This file contains metadata about your chart.
- `values.yaml`: This is where default configuration values for your chart are declared.
- `charts/`: If your chart depends on other charts, they are stored here.
- `templates/`: This directory contains the templates that will generate Kubernetes manifest files

Step 3: Modifying the Chart

Great! With that out of the way, you can now modify the chart to fit your app's requirements. Here, we'll focus on the `templates` directory, which contains a set of files for various Kubernetes resources.

Let's take `deployment.yaml` as an example:

Notice the `{{ }}` syntax. These are Go template directives that are replaced with values when the chart is rendered.

Step 4: Configuring Values

In the `values.yaml` file, you can configure the default values for your templates. For example, if you want to set the default number of replicas to 3, you can modify `values.yaml` as follows:

Then, in your `deployment.yaml` template, you can use `.Values.replicaCount` to refer to this value.

Step 5: Testing Your Chart

After you've configured your template and values, you can test your chart with the `helm install` command

This command will show you the rendered templates with your values, but won't actually deploy anything.

Step 6: Deploying Your Chart

Once you've added your finishing touches, you can deploy it to the Kubernetes cluster using the `helm install` command without the `--dry-run` flag.

For example:

And that's how the magic is made! 

One of the most powerful ways to standardize and streamline your deployments is by creating a Helm Chat Template!