How to Use the Command 'helm' (with examples)
Helm is a package manager for Kubernetes that simplifies the process of deploying and managing applications within a Kubernetes cluster. By streamlining the deployment workflows, Helm allows you to define, install, and upgrade even the most complex Kubernetes applications. It uses “charts,” which are packages of pre-configured Kubernetes resources. Helm can drastically improve operational efficiency by allowing for version control and easy reusability of Kubernetes configurations.
Creating a Helm Chart
Code:
helm create chart_name
Motivation:
The creation of a Helm chart is the first step in packaging a Kubernetes application. Consider it like starting a new project in your favorite IDE. By using helm create
, you’re scaffolded a directory structure with files to aid you in defining, documenting, and configuring your application.
Explanation:
helm
: Invokes the Helm command-line tool.create
: This subcommand initializes a new Helm chart.chart_name
: This is the name you give to your new chart, and it will dictate the name of the directory created.
Example output:
Creating chart 'chart_name' in the current directory
Adding a New Helm Repository
Code:
helm repo add repository_name
Motivation: A Helm repository is a collection of Helm charts. Adding a repository to Helm links your local Helm client to a remote chart source. This is similar to adding package repositories to your operating system’s package manager to install or manage software packages easily.
Explanation:
helm
: Initiates the Helm command.repo
: Specifies that our command will affect Helm repositories.add
: Adds a new repository to your Helm environment.repository_name
: The unique identifier for the repository you wish to add.
Example output:
"repository_name" has been added to your repositories
Listing Helm Repositories
Code:
helm repo list
Motivation: Being able to list all available Helm repositories is essential for managing and updating existing configurations. This command gives an overview of all the remote sources you can pull charts from, thereby providing a list of potential Helm charts you can install.
Explanation:
helm
: Calls the Helm CLI.repo
: Specifies operations related to repositories.list
: Outputs all the repositories currently added to your Helm configuration.
Example output:
NAME URL
repository_1 https://example.com/repo1
repository_2 https://example.com/repo2
Updating Helm Repositories
Code:
helm repo update
Motivation: Helm repositories need to be updated regularly to fetch the latest charts and versions available. Similar to running an update command for system packages, this ensures that your repository metadata is current.
Explanation:
helm
: Calls the Helm software.repo
: Deals with repository interactions.update
: Refreshes the local cache of repository listings.
Example output:
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "repository_name" chart repository
Update Complete.
Deleting a Helm Repository
Code:
helm repo remove repository_name
Motivation: Removing a repository can be necessary if it is no longer needed or if it has been deprecated. It keeps your list of repositories clean and manageable.
Explanation:
helm
: Initiates the Helm tool.repo
: Specifies operations related to repositories.remove
: Deletes a repository from your configuration.repository_name
: The specific repository you want to remove.
Example output:
"repository_name" removed from repositories
Installing a Helm Chart
Code:
helm install name repository_name/chart_name
Motivation: Once a chart is ready, installing it into your Kubernetes cluster is like deploying your application. This command will set up your application according to the specifications in the chart.
Explanation:
helm
: Begins the Helm operation.install
: Deploys a Helm chart.name
: The name you’ll assign to this release of the chart.repository_name/chart_name
: Refers to the exact chart you wish to install by specifying both the repository and chart name.
Example output:
NAME: name
LAST DEPLOYED: Wed Sep 15 17:37:42 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
Downloading a Helm Chart as a Tar Archive
Code:
helm get chart_release_name
Motivation: Downloading a Helm chart as a tar file allows you to transfer or back up the chart in a portable format. This is useful for sharing or examining the chart’s structure without installing it to a cluster.
Explanation:
helm
: Initiates the Helm command-line interface.get
: The command used to download a chart.chart_release_name
: The name of the chart release you want to download.
Example output:
chart_directory/
chart_directory/templates/
chart_directory/values.yaml
chart_directory/Chart.yaml
Updating Helm Dependencies
Code:
helm dependency update
Motivation:
Helm charts can have dependencies specified in Chart.yaml
. Managing complex applications with dependencies needs proper version management and updates. This command refreshes the chart dependencies, essential for keeping them consistent with their expected versions.
Explanation:
helm
: Executes the Helm CLI.dependency
: Focuses on chart dependencies.update
: Synchronizes the specified dependencies based on the data inChart.yaml
.
Example output:
Getting updates for unmanaged Helm repositories...
Saving 1 charts
Dependency '$dependency_name' updated successfully
Conclusion
Helm is an essential tool for anyone working with Kubernetes. This article has illustrated various use cases for Helm commands, each serving specific needs in the development and management of Kubernetes applications. By learning to use Helm effectively, you’re well-equipped to administer scalable, multi-faceted applications seamlessly.