Helm and Kubernetes

Varshitha G
5 min readSep 7, 2022

Step 1: Create Your Kubernetes Cluster

To install Helm into your Kubernetes Cluster you’ll first need a Kubernetes Cluster. I’ve created some scripts to make this easier as creating the Cluster isn’t the purpose of this article. If you go to your Google Cloud Shell scripting you can enter in the following commands to create a Google Kubernetes Cluster ready for Helm.

New Kubernetes Cluster

Second, Install Helm

With your Kubernetes Cluster up and running you can start adding in Helm. Below you will see the actual scripts (with notes) necessary to add a very basic Helm installation into GKE.

#!/usr/bin/env bashecho "install helm"
# installs helm with bash commands for easier command line integration
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
# add a service account within a namespace to segregate tiller
kubectl --namespace kube-system create sa tiller
# create a cluster role binding for tiller
kubectl create clusterrolebinding tiller \
--clusterrole cluster-admin \
--serviceaccount=kube-system:tiller
echo "initialize helm"
# initialized helm within the tiller service account
helm init --service-account tiller
# updates the repos for Helm repo integration
helm repo update
echo "verify helm"
# verify that helm is installed in the cluster
kubectl get deploy,svc tiller-deploy -n kube-system

Now that you’ve seen the code necessary, you can be lazy and just run a script to do the install for you.

$ cd ~/kubernetes-series/helm/scripts
$ sh add_helm.sh

You’ll see everything run through your Shell console very quickly but in the end you should see the following lines, showing that Helm was installed completely.

NAME                   DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/tiller-deploy 1 1 1 0 1s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/tiller-deploy ClusterIP 10.11.244.223 <none> 44134/TCP 1s

You can even do a double check by running a basic Helm command and see the output.

$ helm ls # empty result as we haven't installed anything

Third, Install A Chart

Now with Helm installed, let’s use it! In the scripts to follow we are going to install Redis into our Kubernetes Cluster with some production values recommended by the Redis Chart maintainers.

$ helm install stable/redis \
--values values/values-production.yaml \
--name redis-system

This will only take a moment but we can see that the Redis Chart was successfully deployed by running the following command.

$ helm ls
NAME REVISION UPDATED STATUS CHART NAMESPACE
redis-system 1 Thu Aug 9 11:02:23 2018 DEPLOYED redis-3.7.5 default

If we give the Pods a moment to startup fully you can return to your Kubernetes > Workloads view and see the Pods all ready for you to interact with them.

Install The Helm Command Line Tool

If you’re trying to install Helm (and Tiller) into your Kubernetes Cluster… this isn’t the article right now — you should check out my other articles on just that topic.

helm — The Kubernetes Package Manager

github.com

For my own environment I simply ran the following command to include Helm into my computer:

$ brew install kubernetes-helm

After a moment Helm will be installed and you’ll be good to go.

Run Helm Create

With Helm’s Command Line Tool installed on your compute we can get to work. First, go to your wonderful Kubernetes ready service that you need to turn into a Helm Chart. I have need a microservice to play with in my repo if you need one.

With your service ready you just need to go to the directory and run the helm create command.

$ cd /to/your/folder
$ helm create endpoints
# endpoints is the name of your chart

This will create a Helm Chart setup that you will need to edit into Helm Chart.

The Basic Helm Chart Folder Structure

Next we will go into editing the deployment.yaml and service.yaml files.

Note: If you change the name of your Chart in the yaml files then you will need to update the folder name for your Chart to match the new name. I know because I wanted the folder to be named helm/ and the build step complained about the difference in name.

Start With Your Basic Kubernetes YAML File

Do you have working Kubernetes YAML files? Do you want to just use those files? Great! We can do just that. The easiest, most basic Chart is just your original Kubernetes YAML files. We can just copy over the deployment.yaml and service.yaml files without any editing and you’re done. You don’t even have to read about putting templates and variables in your Charts.

Just A Basic Copy/Replace Of The deployment.yaml And service.yaml File

Customize With Template Variables

If you looked at the generated deployment.yaml and service.yaml files you would see a lot of the following code.

apiVersion: apps/v1beta2
kind: Deployment # it is a deployment
metadata:
name: {{ template “chart.fullname” . }} # name of the Deployment
labels:
# any Pods with matching labels are included in this Deployment
app: {{ template “chart.name” . }}
chart: {{ template “chart.chart” . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
# ReplicaSet specification
replicas: {{ .Values.replicaCount }} # we are making 3 Pods
selector:...

These are values that are inserted when the Helm Chart is installed. This helps you customize the Chart to your liking by injecting new values or providing a custom values.yaml. Speaking of values.yaml, it is important that we look at where all of these values come from for our template.

There are three types of variables I’ve highlighted in the above snippet.

{{ template “chart.fullname” . }} # values from Chart.yaml 
{{ .Release.Name }} # built in Release object
{{ .Values.replicaCount }} # value from values.yaml

You can edit the “chart.____” values in the Chart.yaml file. You can add your own values into the values.yaml to effect .Values._____ values. The .Release.______ values are based on the built-in Release object.

There are more built-in types that I haven’t touched on along with some cool templating features to checkout.

By editing the values you can eventually get to a good custom template that has all the right values and can do all the things you need.

Install Your Helm Chart

Now we are ready to install our endpoints Helm Chart onto any Kubernetes Cluster. Right now we are going to look at running this install locally from your bash environment. You could also run the install from a published Helm Chart.

Let’s say you have an installable Helm Chart ready, we can install it into our active Kubernetes Cluster with the following command.

$ helm install --name endpoints path/to/chart/endpoints

This will install the Helm Chart using all of the defaults built into the Chart. What if we wanted to change a single value in the values.yaml file? We can do that easily with the set command.

$ helm install --name endpoints path/to/chart/endpoints \
--set image.project=my-project

Changed. This is why you put all of your variables into the values.yaml file.

Want to see output before it is installed to ensure things look correct? Try the following command.

$ helm install --name endpoints path/to/chart/endpoints \
--set image.project=my-project \
--dry-run --debug

By adding the dry-run and debug flags I’ve stopped the Helm Chart from installing and viewed the output.

Artifacthub.io helm chart repo URL:

https://artifacthub.io/packages/helm/kvaps/kubernetes

Thank you for reading!!

--

--

Varshitha G

My Belief - Nobody is Born Programmer . I'm an IT Enthusiast and Inquisitive about Modern Technologies. Blogger at csestack.org, pcskull.com. ARTH Learner