Kubernetes: Creating and Publishing Your Own Helm Charts

Updated: February 1, 2024 By: Guest Contributor Post a comment

Introduction

Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers. With the growing complexity of services deployed on Kubernetes, managing applications and their deployments has become increasingly challenging. Enter Helm, the package manager for Kubernetes, which simplifies the process of defining, installing, and upgrading even the most complex Kubernetes applications.

In this tutorial, we’ll explore the steps involved in creating and publishing your own Helm charts. We’ll walk you through this process, providing both the knowledge and hands-on code examples you’ll need to package and distribute your Kubernetes applications with ease.

Getting Started with Helm

Before diving into chart creation, make sure you have both Kubernetes and Helm installed. Depending on your Kubernetes cluster setup, the installation process may vary. For local development, Minikube is an excellent way to get started with a Kubernetes cluster.

Once Kubernetes is up and running, install Helm by following the instructions on the Helm documentation page.

curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

Verify the installation:

helm version

Creating a Helm Chart

Helm packages are called charts. A chart is a collection of files that describes a related set of Kubernetes resources. To create a new chart:

helm create myapp

The helm create command will scaffold out the structure of a chart repository. This skeletal chart provides you with a pre-configured set of resources to get started. The directory structure should look like this:

myapp/
|-- Chart.yaml
|-- charts/
|-- templates/
|-- values.yaml

Chart.yaml: Stores metadata about the chart such as the name, version, and description.
charts/: Directory for chart dependencies.
templates/: Kubernetes resource templates configured to pull values from the values.yaml file.
values.yaml: Default value overrides for the chart.

Customizing Chart Values

The values.yaml file contains default values for a chart’s templates. Customize these values to suit your application:

replicaCount: 3
image:
 repository: myapp
 tag: v1.0.0

These values can be overridden at install or upgrade time. Providing a custom values.yaml is a way to deploy the same chart with different configurations.

Packaging the Helm Chart

Once your chart is complete and ready to be shared, package it using the helm package command:

helm package myapp

This command will create a versioned archive file of your chart.

Publishing the Helm Chart

To make your chart available to others, you need to publish it to a chart repository. A repository is a place where packaged charts can be collected and shared. You can host your own chart repository or use a public one like Helm Hub. For simplicity, we’ll use GitHub to host our repository.

Create a new GitHub repository to store your Helm charts. Then, clone the repository to your local system and move your packaged chart to the repository’s directory:

git clone https://github.com/your_github/my-helm-repo.git
mv myapp-0.1.0.tgz my-helm-repo/
cd my-helm-repo
git add myapp-0.1.0.tgz
git commit -m "Adding myapp chart"
git push

You’ll also need an index file for your repository, which can be generated by running:

helm repo index . --url https://your_github.github.io/my-helm-repo

Commit and push the index.yaml file as well.

To use the GitHub Pages service to host your chart, navigate to the repository settings on GitHub and enable GitHub Pages for your repository. You should now be able to add your new repository as a Helm repo:

helm repo add my-helm-repo https://your_github.github.io/my-helm-repo

To install a chart from your newly published repository, run:

helm install myapp my-helm-repo/myapp

That’s it! You’ve just created and published a Helm chart.

Best Practices for Helm Chart Development

Here are a few best practices to keep in mind when creating Helm charts:

  • Name your charts succinctly and clearly.
  • Use semantic versioning to version your charts.
  • Provide comprehensive values.yaml examples.
  • Include resource requests and limits to ensure that apps work well in different Kubernetes environments.
  • Maintain backwards compatibility within major chart versions.
  • Document any pre-requisites or dependencies in the README.md.

By following these guidelines and leveraging Helm’s capabilities, you can streamline Kubernetes application management and share your applications with the broader Kubernetes community with ease.