Helm for Kubernetes

Table of Contents

  1. Overview
  2. What is Helm?
  3. Why Use Helm?
  4. Installing Helm
  5. Managing Kubernetes Applications with Helm
  6. Creating and Deploying Helm Charts
  7. Best Practices for Using Helm
  8. Conclusion

Overview

Helm is a package manager for Kubernetes that simplifies deployment and management of applications on Kubernetes clusters. It allows you to define, install, and upgrade even the most complex Kubernetes applications through reusable packages called charts. In this module, we’ll explore how to get started with Helm, how to install and use it, and how to create and deploy your own Helm charts.


What is Helm?

Helm is often described as the Kubernetes package manager. It allows users to:

  • Package Kubernetes applications: With Helm charts, applications and services are packaged in a way that simplifies deployment.
  • Manage complex Kubernetes applications: Helm charts allow you to define Kubernetes resources (like Deployments, Services, ConfigMaps, and Secrets) in one place.
  • Simplify upgrades and versioning: Helm makes it easy to update, rollback, and manage different versions of Kubernetes applications.

Helm’s core concepts include charts, repositories, releases, and values.


Why Use Helm?

  1. Reusable Packages (Charts): Helm allows you to define Kubernetes applications once as reusable, customizable charts, saving time and avoiding redundant configuration.
  2. Simplified Configuration Management: You can maintain complex configurations across various environments (development, staging, production) through easy-to-manage values files.
  3. Versioned Releases: Helm allows you to keep track of versions and manage the release lifecycle, including rolling back to previous versions.
  4. Community and Ecosystem: Helm charts are widely used in the Kubernetes ecosystem, and many open-source applications have pre-built charts ready for deployment.

Installing Helm

Before using Helm, you must install it on your local machine.

Installing Helm on macOS, Linux, and Windows

  • macOS (using Homebrew): bashCopyEditbrew install helm
  • Linux: Download the latest release from the Helm GitHub page or use the following commands: bashCopyEditcurl -fsSL https://get.helm.sh/helm-v3.8.0-linux-amd64.tar.gz -o helm.tar.gz tar -xvf helm.tar.gz sudo mv linux-amd64/helm /usr/local/bin/helm
  • Windows (using Chocolatey): bashCopyEditchoco install kubernetes-helm

Once installed, verify Helm installation by checking its version:

bashCopyEdithelm version

Managing Kubernetes Applications with Helm

Helm simplifies the management of Kubernetes applications, providing key commands to interact with your applications.

Helm Chart Structure

A Helm chart is a collection of files that describe a related set of Kubernetes resources. It typically includes the following files:

  • Chart.yaml: Defines the metadata of the chart (name, version, etc.)
  • values.yaml: Default configuration values that can be overridden when installing the chart
  • templates/: Contains Kubernetes manifests (YAML files) that are rendered with values from values.yaml
  • charts/: Sub-charts (dependencies) that are included with your chart
  • README.md: Describes how to use the chart

Basic Helm Commands

Helm provides a set of commands to manage Kubernetes applications. Here are some key commands:

  • helm search: Search for charts in a repository bashCopyEdithelm search repo <chart-name>
  • helm install: Install a chart to your Kubernetes cluster bashCopyEdithelm install <release-name> <chart-name>
  • helm upgrade: Upgrade an existing release bashCopyEdithelm upgrade <release-name> <chart-name>
  • helm rollback: Roll back a release to a previous version bashCopyEdithelm rollback <release-name> <revision-number>
  • helm list: List installed releases bashCopyEdithelm list
  • helm uninstall: Uninstall a release bashCopyEdithelm uninstall <release-name>

Creating and Deploying Helm Charts

Creating a Helm Chart

To create a new Helm chart, use the following command:

bashCopyEdithelm create mychart

This will create a new directory mychart/ with the basic structure for your Helm chart.

Deploying with Helm

After creating or modifying a Helm chart, you can deploy it to Kubernetes by running:

bashCopyEdithelm install myrelease ./mychart

This will deploy your application using the resources defined in mychart/.

Updating and Rolling Back Releases

To update a release, simply modify the chart or values and run:

bashCopyEdithelm upgrade myrelease ./mychart

If needed, you can roll back to a previous version of the release:

bashCopyEdithelm rollback myrelease 1

This command will roll back the release to revision 1.


Best Practices for Using Helm

  • Use Version Control: Keep your Helm charts in version control (e.g., Git) to track changes and maintain history.
  • Use Sub-charts: Leverage Helm’s ability to manage dependencies by including sub-charts to manage complex setups.
  • Use values.yaml for Customization: Avoid hard-coding values directly into templates. Use values.yaml to manage configurations in a flexible, environment-agnostic manner.
  • Test Before Deploying: Test Helm charts locally or in a test environment before deploying to production.
  • Manage Configurations per Environment: Use separate values files for each environment (e.g., values-dev.yaml, values-prod.yaml) and deploy accordingly.
  • Chart Repositories: Host your charts in a private chart repository if your project requires it, using Helm’s support for Helm repositories.
  • Use helm template for Debugging: If you encounter issues, use helm template to render your templates locally and inspect them.

Conclusion

Helm is a powerful tool for managing Kubernetes applications. By enabling reusable, versioned configurations and simplifying complex deployments, Helm improves productivity and ensures consistency across environments. With the ability to create, update, and roll back applications seamlessly, Helm has become an essential tool for Kubernetes developers and DevOps teams.