How to Create a Helm Chart and Deploy It on Kubernetes

November 14, 2024

Introduction

Helm charts optimize the deployment of Kubernetes resources by packaging resource manifests into reusable YAML template bundles.

Users can easily configure the charts to adapt to any scenario, which allows for efficient and consistent deployment of complex applications.

This article provides step-by-step instructions on how to create and deploy a Helm chart.

How to create a Helm chart.

Prerequisites

Note: To confirm Helm has been installed properly, run which helm in the terminal. The output should return a path to Helm.

How to Create Helm Chart

Creating a Helm chart involves generating the chart directory using the Helm CLI. Enter the following command to create a new chart:

helm create [chart_name]

For example:

helm create phoenixnap

The output confirms Helm executed the action successfully.

Creating a Helm chart using helm create command.

List the chart structure with the ls command:

ls [chart_name]
Using the ls command to list the Helm chart structure.

The Helm chart directory contains the following items:

  • charts - The directory storing dependent charts.
  • templates - The directory for configuration files.
  • Chart.yaml - The file containing chart metadata.
  • values.yaml - The file with default chart parameter values.

How to Configure Helm Chart

Configuring a helm chart involves customizing parameters such as the image pull policy, name override, service account, and service type. Follow the steps below to learn how to edit these parameters in the values.yaml file.

Configure Helm Chart Image Pull Policy

The image pull policy determines how a container image is pulled from a registry. The default policy value is IfNotPresent, meaning that Kubernetes pulls an image only if it is not already on the system. To change this behavior:

1. Open the values.yaml file in a text editor such as Nano:

nano [chart_name]/values.yaml

2. Locate the image section.

Default pull policy in the values.yaml file.

There are three possible values for pullPolicy:

  • IfNotPresent - Download the image if it does not exist in the cluster.
  • Always - Pull the image on every restart or deployment.
  • Latest - Pull the most up-to-date version available.

3. Change the pull policy from IfNotPresent to Always:

Changed pull policy to Always in the values.yaml file.

Helm Chart Name Override

To override the chart name in the values.yaml file, add values to nameOverride and fullnameOverride fields. The following example adds phoenix-app as the nameOverride value and phoenix-chart as fullnameOverride.

Changed chart name override values in the values.yaml file

Overriding the Helm chart name ensures configuration files also change.

Specify Service Account Name

The service account name for the Helm chart is generated when you run the cluster. However, it is good practice to set it manually and ensure the application is directly associated with a controlled user in the chart.

To provide a custom service account name, locate the serviceAccount value in the values.yaml file and specify the name of the service account. The example below shows phoenixnap as the name of the service account.

Changed service account name in the values.yaml file

Change Networking Service Type

Depending on the cluster, a deployment may require different networking service types. For example, when using Minikube for testing, the recommended networking service type is NodePort.

To change the networking service type, locate the service section and change the value in the type field. The example below shows NodePort set as the new service type.

Changed service type in the values.yaml file.

How to Deploy New Helm Chart on Kubernetes

After configuring the values.yaml file, deploy the application using Helm commands. Proceed with the steps below to complete this action.

Step 1: Install Helm Chart

Install the Helm chart using the helm install command:

helm install [full_name_override] [chart_name]/ --values [chart_name]/values.yaml

For example:

helm install phoenix-chart phoenixnap/ --values phoenixnap/values.yaml
Installing helm chart with helm install command.

The helm install command deploys the app.

Step 2: Export Node Port and IP Address

Run the two export commands printed in the NOTES section of the helm install output. For example, the output for the phoenix-chart deployment in the default namespace generates the following commands:

export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services phoenix-chart)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")

The commands produce no output but store the IP and port values in respective environment variables.

Step 3: View the Deployed Application

To view the contents of the environment variables from the previous step, enter the following echo command:

echo http://$NODE_IP:$NODE_PORT

The output shows the full address of the deployed application.

Terminal output of the command echo address.

Copy the address and paste it into a web browser. The application screen appears.

Checking if the deployed helm chart and application are working.

Note: Learn how to delete a Helm deployment and namespace to remove unwanted or multiple copies of Helm deployments.

Conclusion

By following this step-by-step guide, you learned how to create a Helm chart tailored to your needs. Once configured, the chart can be seamlessly deployed to your Kubernetes cluster.

Now that you know how to create a Helm chart, learn How to pull and push Helm charts and add Helm chart repositories.

Was this article helpful?
YesNo
Milica Dancuk
Milica Dancuk is a technical writer at phoenixNAP with a passion for programming. With a background in Electrical Engineering and Computing, coupled with her teaching experience, she excels at simplifying complex technical concepts in her writing.
Next you should read
How to Add, Update or Remove Helm Repositories
December 21, 2020

Helm is Kubernetes' equivalent to apt and yum. It is a package manager used for deploying applications...
Read more
How to Install Helm on Ubuntu, Mac and Windows
October 30, 2024

Helm is a package manager for Kubernetes that simplifies deployment process. Follow this step-by-step...
Read more
19 Kubernetes Best Practices for Building Efficient Clusters
August 29, 2024

Kubernetes is a feature-rich orchestration tool. The best practices outlined in this article are going to...
Read more
How to Install Minikube on Ubuntu 18.04 / 20.04
April 30, 2020

Follow this step-by-step tutorial to install Minikube on your Ubuntu 18.04. Minikube allows you to work in...
Read more