Using Helm Charts
Using Helm Charts
Now that you have a solid understanding of what Helm charts are and how they are structured, it's time to put that knowledge into practice. In this lesson, we will explore how to use Helm charts to deploy applications to a Kubernetes cluster. You’ll learn how to find and download Helm charts from public repositories, install charts on your Kubernetes cluster, and manage Helm releases. By the end of this lesson, you’ll be equipped to deploy applications quickly and efficiently using Helm.
Finding and Downloading Helm Charts
The first step in using Helm charts is to find the chart that suits your needs. Helm charts are typically stored in repositories, which are collections of charts that can be publicly or privately hosted. There are many public Helm repositories available where you can find charts for a wide range of applications.
Popular Helm Repositories
Artifact Hub: A central hub for finding and sharing Kubernetes packages, including Helm charts. It aggregates charts from various repositories and is a great place to start your search.
Bitnami: A popular Helm repository known for its well-maintained and widely used charts for applications like Nginx, WordPress, and MySQL.
Stable Repository: Once the official Helm repository, now deprecated but still widely used through mirrors or forks.
Commands to interact with repositories:
Adding a Repository: Before you can use a chart, you need to add the repository to Helm.
Listing Repositories: You can list all added repositories to see what’s available.
Searching for Charts: Once the repository is added, you can search for specific charts.
Downloading a Chart
While you can directly install charts from a repository, you might want to download a chart first to inspect or modify it.
Command to Download a Chart:
Download a Chart: This command fetches the chart files from the repository.
The
--untar
flag extracts the chart into a directory, so you can explore its contents.
Installing a Helm Chart
Once you’ve identified the chart you want to use, installing it on your Kubernetes cluster is straightforward. Helm makes it easy to deploy an application with a single command.
Basic Installation
To install a chart, you use the helm install
command. This command requires at least two arguments: a release name (a unique name for your deployment) and the chart to install.
Command to Install a Chart:
Installing a Chart:
my-nginx
: This is the name of the release.bitnami/nginx
: This specifies the chart from the Bitnami repository.
After running this command, Helm will:
Render the chart’s templates using the default or provided values.
Interact with the Kubernetes API to create the necessary resources.
Record the release in Helm’s history, allowing you to manage it later.
Customizing Installation with Values
One of the strengths of Helm is its ability to customize deployments using the values.yaml
file. You can override these values at the time of installation using the --set
flag or by providing a custom values file.
Customizing with --set
Flag:
Command to Set a Custom Value:
This command overrides the default service type, setting it to
NodePort
.
Customizing with a Custom Values File:
Using a Custom Values File:
Here,
custom-values.yaml
contains your custom configuration.
Verifying the Installation
After installation, it’s essential to verify that everything was set up correctly.
Commands for Verifying Installation:
List Releases: Shows all the current releases in your cluster.
Get Release Status: Provides detailed information about a specific release.
Check Kubernetes Resources: Use
kubectl
to see the created resources.
Managing Helm Releases
Helm doesn’t just stop at installing applications. It also provides powerful tools for managing your releases over time, including upgrading, rolling back, and uninstalling them.
Upgrading a Release
As your application evolves, you may need to upgrade your Helm release. This could involve updating to a new chart version or simply changing some configuration values.
Command to Upgrade a Release:
Upgrade Release:
This command upgrades the
my-nginx
release to use a different image tag.
Rolling Back a Release
If something goes wrong with an upgrade, Helm allows you to roll back to a previous release version.
Command to Roll Back a Release:
Rollback Release:
This command rolls back the
my-nginx
release to version 1.
Uninstalling a Release
When you no longer need an application, you can uninstall the release. This command deletes all Kubernetes resources associated with the release.
Command to Uninstall a Release:
Uninstall Release:
Helm will clean up all the resources and remove the release from its history.
Hands-on Example: Deploying Nginx with Helm
To solidify your understanding, let’s walk through a hands-on example of deploying Nginx using a Helm chart.
Steps:
Add the Bitnami Repository:
Install the Nginx Chart:
Verify the Installation:
Upgrade the Nginx Release:
Rollback the Release if Needed:
Uninstall the Release:
This example walks you through the complete lifecycle of a Helm release, from installation to uninstallation, giving you hands-on experience with the Helm CLI.
Summary
Using Helm charts to deploy applications on Kubernetes is a powerful and efficient way to manage your infrastructure. Helm simplifies the process of installing, upgrading, and managing applications, allowing you to focus on building and running your services rather than dealing with the complexities of Kubernetes resource management. By mastering the basics of using Helm charts, you’re well on your way to becoming proficient in Kubernetes application management.
Last updated