Helm is an essential tool for Kubernetes application deployment, enabling developers to streamline the process of managing, upgrading, and rolling back Kubernetes applications. This article will provide an in-depth overview of creating a custom helm chart using the widely popular Bitnami template. By the end of the article, you will have a comprehensive understanding of Helm and its usage in deploying custom helm charts on production clusters while adhering to the best practices of the Kubernetes community.

Table of Contents

  1. Introduction to Helm
  2. Prerequisites for Creating a Custom Helm Chart
  3. Generating a Helm Chart with a Bitnami Template
  4. Understanding the Helm Chart Structure
  5. Working with Templates and Values
  6. Adding Dependencies and Managing Releases
  7. Deploying the Custom Helm Chart
  8. Modifying the Chart for a Custom Service
  9. Packaging and Sharing the Helm Chart
  10. Conclusion

Introduction to Helm

Helm is a package manager for Kubernetes applications that simplifies the deployment, scaling, and management of applications on Kubernetes clusters. It is designed to help developers manage the complexity of deploying cloud-native applications by providing a structured approach to defining, packaging, and distributing Kubernetes applications.

Helm uses a packaging format called “charts” which are collections of files that describe a related set of Kubernetes resources. Charts can be used to deploy simple applications like a standalone web server or more complex applications, such as a multi-tier web application with a backend database.

Prerequisites for Creating a Custom Helm Chart

Before diving into creating a custom Helm chart, it is essential to have the following prerequisites:

  1. A Kubernetes cluster up and running.
  2. Helm installed on your local machine.
  3. A basic understanding of Kubernetes objects such as Deployments, Services, and ConfigMaps.
  4. Familiarity with Bitnami templates, a widely used Helm chart template.

Generating a Helm Chart with a Bitnami Template

Once you have the prerequisites in place, you can start creating a custom Helm chart using a Bitnami template. The first step is to generate a new Helm chart using the helm create command:

helm create mychart

This command will generate a new Helm chart directory named mychart, which will contain the necessary files and structure for creating a custom Helm chart.

Understanding the Helm Chart Structure

After generating a new Helm chart, it’s essential to understand the chart’s structure and the purpose of each file. The typical structure of a Helm chart is as follows:

mychart/
|-- Chart.yaml
|-- charts/
|-- templates/
|   |-- NOTES.txt
|   |-- _helpers.tpl
|   |-- deployment.yaml
|   |-- ingress.yaml
|   `-- service.yaml
`-- values.yaml

Here is a brief overview of the key components of a Helm chart:

  • Chart.yaml: This file contains metadata about the chart, such as the chart’s name, version, and description.
  • charts/: This directory contains any sub-charts or dependencies for the main chart.
  • templates/: This directory contains the YAML definitions for Kubernetes objects, such as Deployments, Services, and ConfigMaps. These files use the Go Template Engine for templating.
  • values.yaml: This file contains default values for the chart’s configurable parameters. Users can override these defaults when installing the chart.

Working with Templates and Values

Templates and values are the core components of a Helm chart, providing a way to customize the chart’s deployment based on user-defined parameters.

Templates

The templates/ directory contains the YAML definitions for Kubernetes objects, such as Deployments, Services, and ConfigMaps. These files use the Go Template Engine for templating, which allows developers to create dynamic templates that can be customized based on user input.

For example, the service.yaml file in the templates/ directory might look like this:

apiVersion: v1
kind: Service
metadata:
  name: {{ template "fullname" . }}
  labels:
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.externalPort }}
      targetPort: {{ .Values.service.internalPort }}
      protocol: TCP
      name: {{ .Values.service.name }}
  selector:
    app: {{ template "fullname" . }}

When deploying the chart, Helm will generate a valid Service definition based on the provided values.

Values

The values.yaml file contains default values for the chart’s configurable parameters. Users can override these defaults when installing the chart.

For example, the values.yaml file might look like this:

replicaCount: 1

image:
  repository: myapp
  tag: 1.0.0
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  externalPort: 80
  internalPort: 80
  name: myapp

To customize the chart’s deployment, users can provide their own values.yaml file or override specific values using the --set flag when installing the chart.

Adding Dependencies and Managing Releases

Helmcharts can include dependencies on other charts, allowing developers to build complex applications with multiple components. To add a dependency to your chart, create a requirements.yaml file in the root directory of your chart:

dependencies:
  - name: redis
    version: "15.0.0"
    repository: "https://charts.bitnami.com/bitnami"

This example adds a dependency on the Bitnami Redis chart. To fetch the dependencies and update your chart, run:

helm dependency update ./mychart

Helm will download the specified Redis chart and place it in the charts/ directory of your chart.

Managing Releases

Helm tracks the history of each release, allowing developers to manage upgrades, rollbacks, and audits of their applications. To view the list of deployed releases, use the helm list command:

helm list

To uninstall a release, use the helm uninstall command:

helm uninstall my-release

This command will remove all resources associated with the release, as well as the release history. If you want to keep the release history, you can use the --keep-history flag:

helm uninstall my-release --keep-history

With Helm, you can easily manage and maintain the lifecycle of your Kubernetes applications, ensuring smooth upgrades and rollbacks when needed.

Deploying the Custom Helm Chart

After creating your custom Helm chart and adding dependencies, you can deploy it to your Kubernetes cluster using the helm install command:

helm install my-release ./mychart

This command will deploy your chart with the provided release name my-release. You can monitor the deployment’s progress using kubectl or the Kubernetes dashboard.

Once the deployment is complete, you can access your application using the appropriate service or ingress configuration specified in your chart.

Modifying the Chart for a Custom Service

You can easily modify the Helm chart to deploy a custom service by updating the values.yaml file and the template files in the templates/ directory. For example, to deploy a custom web application, you can update the values.yaml file with the appropriate image and service configuration:

image:
  repository: my-web-app
  tag: 1.0.0
  pullPolicy: IfNotPresent

service:
  type: LoadBalancer
  externalPort: 80
  internalPort: 8080
  name: my-web-app

Then, update the deployment.yaml file in the templates/ directory to use the new image and service configuration. Make any necessary changes to the service.yaml file and other template files as needed.

After making the necessary changes, you can deploy your custom service using the helm install command as described in the previous section.

Packaging and Sharing the Helm Chart

Once you have created and tested your custom Helm chart, you may want to package and share it with others. To package your chart, use the helm package command:

helm package ./mychart

This command will create a .tgz file containing your chart files and metadata. You can then distribute this package to others or host it on a Helm chart repository for easy installation.

To share your chart using a Helm repository, you can host your own repository using a web server, or use a hosted repository solution like Artifact Hub, ChartMuseum, or Harbor.

Conclusion

In this article, we have explored the basics of Helm and how to create a custom Helm chart using a Bitnami template. By leveraging Helm, developers can simplify the deployment and management of their Kubernetes applications and ensure a consistent and reliable deployment process.

By following the steps outlined in this article, you can create and deploy your custom Helm charts with ease, manage dependencies, and share your charts with others in the Kubernetes community. So go ahead and start creating your custom Helm charts using Bitnami templates to make the most of your Kubernetes deployments.