Create a Helm chart & deploy a Kubernetes application using it.

Shashank Srivastava
4 min readOct 5, 2021

--

Learn how to create a Helm chart & use it to deploy a Kubernetes application in a few easy steps.

Introduction.

In this post, I’ll show you how we can create a Helm chart & deploy our Kubernetes application. I have kept everything simple because my goal is to get you started with Helm rather quickly. That is why the setup & the steps are quite simple.

Below is what my setup looks like.

  • Kubectl v1.22.2.
  • Helm v3.7.0
  • Minikube v1.23.2

Requirements.

  • Any Kubernetes cluster (Minikube will also work).
  • Helm 3
  • Docker image of your choice. This image should be available on either Docker Hub or your private Docker registry.

Steps to follow.

1. Create a Helm chart.

Entering this command (helm create mymusicstats) will create the Helm chart & also its directory structure.

shashanksrivastava@MBP ~/Helm Charts> helm create mymusicstats
Creating mymusicstats

Please note that mymusicstats is the name of the chart. The directory will be created with the same name.

This is what the directory structure looks like.

shashanksrivastava@MBP ~/H/mymusicstats> tree
.
├── Chart.yaml
├── charts
├── templates
│ ├── NOTES.txt
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── service.yaml
│ ├── serviceaccount.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
3 directories, 10 files

The most important file here is values.yaml. In this file, we provide the location of the image repository & other details like the service port. We will discuss it in the next step.

2. Edit values.yaml file.

Open this file in your favorite editor & edit the following values.

Change repository to the location of your Docker image. Here I am using my own web application which is hosted on Docker Hub. It is a lightweight image & makes it super convenient for me to use this web application.

Also, change pullPolicy to Always. tag should be the one that is available on Docker Hub/registry.

image:
repository: shashankssriva/mymusicstats
pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion.
tag: "1.0"

Now edit the Service section. Change type to NodePort because we want to access this application from outside the cluster.

service:
type: NodePort
port: 80

3. Edit Chart.yaml file (optional).

This file contains metadata about your Helm chart, such as name & version. You can continue with the default values for the chart & application version or you can change it as per your preference.

4. Deploy the chart.

Here comes the final step. It's time to deploy our application using Helm.

While inside the parent directory of your chart, issue the below command.

shashanksrivastava@MBP ~/H/mymusicstats> helm install mymusicstats . --values values.yaml
NAME: mymusicstats
LAST DEPLOYED: Tue Oct 5 10:43:08 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services mymusicstats)
export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT

You can list your charts now.

shashanksrivastava@MBP ~/H/mymusicstats> helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
mymusicstats default 1 2021-10-05 10:43:08.856211 +0530 IST deployed mymusicstats-0.1.0 1.0.0

Check the service.

shashanksrivastava@MBP ~/H/mymusicstats> kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 4d20h
mymusicstats NodePort 10.108.34.83 <none> 80:32349/TCP 28s

Access your application now.

If you’re using Minikube, simply enter the minikube service <service_name> command & it will automatically open the application in the browser tab.

hashanksrivastava@MBP ~/H/mymusicstats> minikube service mymusicstats
|-----------|--------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|--------------|-------------|---------------------------|
| default | mymusicstats | http/80 | http://192.168.49.2:32349 |
|-----------|--------------|-------------|---------------------------|
🏃 Starting tunnel for service mymusicstats.
|-----------|--------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|--------------|-------------|------------------------|
| default | mymusicstats | | http://127.0.0.1:59078 |
|-----------|--------------|-------------|------------------------|
🎉 Opening service default/mymusicstats in default browser...
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
My web app deployed using Helm.

On other Kubernetes clusters, access the application using <worker_node_IP or hostname:NodePort>.

--

--

Shashank Srivastava
Shashank Srivastava

Written by Shashank Srivastava

DevSecOps Architect @Virtualness. Music/Book/Photography/Fitness lover & Blogger.

Responses (1)