How To Create A Helm Chart

Introduction

Helm charts are one of the best practices for building efficient clusters in Kubernetes. It is a form of packaging that uses a collection of Kubernetes resources. Helm charts use those resources to define an application.

Helm charts use a template approach to deploy applications. Templates give structure to projects and are suitable for any type of application.

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

How to Create and Deploy a Helm Chart

Prerequisites

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

Create Helm Chart

Creating a Helm chart involves creating the chart itself, configuring the image pull policy, and specifying additional details in the values.yaml file.

Step 1: Create a New Helm Chart

1. To create a new Helm chart, use:

helm create <chart name>

For example:

helm create phoenixnap
Creating a helm chart using helm create command

2. Using the ls command, list the chart structure:

ls <chart name>
Using the ls command to list the helm chart structure

The Helm chart directory contains:

  • Directory charts – Used for adding dependent charts. Empty by default.
  • Directory templates – Configuration files that deploy in the cluster.
  • YAML file – Outline of the Helm chart structure.
  • YAML file – Formatting information for configuring the chart.

Step 2: Configure Helm Chart Image Pull Policy

1. Open the values.yaml file in a text editor. Locate the image values:

Default pull policy in the values.yaml file

There are three possible values for the pullPolicy:

  • IfNotPresent – Downloads a new version of the image if one does not exist in the cluster.
  • Always – Pulls the image on every restart or deployment.
  • Latest – Pulls the most up-to-date version available.

2. Change the image pullPolicy from IfNotPresent to Always:

Changed pull policy to Always in the values.yaml file

Step 3: Helm Chart Name Override

To override the chart name in the values.yaml file, add values to the nameOverride and fullnameOverride:

Default chart name override values in the values.yaml file

For example:

Changed chart name override values in the values.yaml file

Overriding the Helm chart name ensures configuration files also change.

Step 4: Specify Service Account Name

The service account name for the Helm chart generates when you run the cluster. However, it is good practice to set it manually.

The service account name makes sure the application is directly associated with a controlled user in the chart.

1. Locate the serviceAccount value in the values.yaml file:

Default service account name in the values.yaml file

2. Specify the name of the service account:

Changed service account name in the values.yaml file

Step 5: Change Networking Service Type

The recommended networking service type for Minikube is NodePort.

1. To change the networking service type, locate the service value:

Default service type in the values.yaml file

2. Change the type from ClusterIP to NodePort:

Changed service type in the values.yaml file

Deploy Helm Chart

After configuring the values.yaml file, check the status of your Minikube cluster and deploy the application using Helm commands.

Step 1: Check minikube Status

If Minikube isn’t running, the install Helm chart step returns an error.

1. Check Minikube status with:

minikube status

The status shows up as Running.

Checking the minikube status before deploying chart

2. If the status shows Stopped, run:

minikube start
Output of the commands minikube status and minikube start

The output shows Done and the status changes to Running.

Step 2: Install the 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. The next steps are printed in the NOTES section of the output.

Step 3: Export the Pod Node Port and IP Address

1. Copy the two export commands from the helm install output.

2. Run the commands to get the Pod node port and IP address:

Terminal output of the commands export node port and ip

Step 4: View the Deployed Application

1. Copy and paste the echo command and run it in the terminal to print the IP address and port:

Terminal output of the command echo address

2. Copy the link and paste it into your browser, or press CTRL+click to view the deployed application:

Checking if the deployed helm chart and application are working.

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

Conclusion

After following the outlined step-by-step instructions, you have a Helm chart created, set up, and deployed on a web server. Helm charts simplify application deployment on a Kubernetes cluster.

Now that you have created a Helm chart, learn How to Pull And Push Helm Charts.

Add Helm chart repositories to create more complex applications, learn how to use environment variables with Helm, or learn about other Kubernetes tools next.

原创文章,作者:745907710,如若转载,请注明出处:https://blog.ytso.com/223913.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

相关推荐

发表回复

登录后才能评论