How to Use Helm With Kubernetes?

Mayank_Agarwal
6 min readApr 29, 2021

Brief introduction about Kubernetes

Kubernetes, at its basic level, is a system for running and coordinating containerized applications across a cluster of machines. It is a platform designed to completely manage the life cycle of containerized applications and services using methods that provide predictability, scalability, and high availability.

As a Kubernetes user, you can define how your applications should run and the ways they should be able to interact with other applications or the outside world. You can scale your services up or down, perform graceful rolling updates, and switch traffic between different versions of your applications to test features or rollback problematic deployments. Kubernetes provides interfaces and composable platform primitives that allow you to define and manage your applications with high degrees of flexibility, power, and reliability.

What is Helm?

In simple terms, Helm is a package manager for Kubernetes. Helm is the K8s equivalent of yum or apt. Helm deploys charts, which you can think of as a packaged application. It is a collection of all your versioned, per-configured application resources which can be deployed as one unit. You can then deploy another version of the chart with a different set of configuration.

Helm helps in three key ways:

  • Improves productivity
  • Reduces the complexity of deployments of micro services
  • Enables the adaptation of cloud native applications

Why use Helm?

Writing and maintaining Kubernetes YAML manifests for all the required Kubernetes objects can be a time consuming and tedious task. For the simplest of deployments, you would need at least 3 YAML manifests with duplicated and hardcoded values. Helm simplifies this process and creates a single package that can be advertised to your cluster.

What are Helm charts?

Helm Charts are simply Kubernetes YAML manifests combined into a single package that can be advertised to your Kubernetes clusters. Once packaged, installing a Helm Chart into your cluster is as easy as running a single helm install, which really simplifies the deployment of containerized applications.

Prerequisites

The following prerequisites are required for a successful and properly secured use of Helm.

  1. A Kubernetes cluster
  2. Deciding what security configurations to apply to your installation, if any
  3. Installing and configuring Helm.

In this blog we will be creating a simple wordpress helm chart having back-end MYSQL connectivity.

Setting up MySQL deployment before configuring wordpress helm chart

As the wordpress requires a back-end database for its functioning , so let us first create a deployment for it .

For this we can use a yaml file for deployment:-

MySQL.yaml deployment file

Run this file using :-

#kubectl apply -f mysql.yaml

After creating deployment expose the services so that wordpress can utilize it using :-

#kubectl expose deploy mysql — port:3306 — type=NodePort

3306 is the by default port number for the MYSQL.

Now let’s configure a helm chart for the wordpress:-

Step1: configure k8s cluster

K8s cluster configured

The cluster shown in above image configured already and used in this tutorial.

Step2: Installing helm

Helm can be installed by using the link mentioned below with the wget command or any other according to the operating system:-

https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz

After downloading helm :-

Unpack it (#tar -zxvf helm-v3.5.2-linux-amd64.tar.gz)

Find the helm binary in the unpacked directory, and move it to its desired destination (mv linux-amd64/helm /usr/bin/)

Step3: Installing helm chart

For installing or creating the helm chart first create a empty directory with the name of the chart you want to create can be done with mkdir command. In our case wordpress.

Now for installing helm chart inside the directory the basic requirement is of chart file having by default name Chart.yaml . Which contains basic information about the helm chart.

Chart.yaml file

Now the helm chart can be installed in the directory by following command helm install [chart_name] [directory_name]/

#helm install wordpress /wordpress

helm installed in the directory

Step4: Adding yaml files in helm chart

For adding the yaml files in the helm chart directory create another directory/folder with the name templates(by default ).

And add all the Yaml files in it. Two files has been used in this configuration

  1. The deployment file having details of environmental values for the back-end MySQL.

wordpress deployment file

2.The service file which alongside expose the services of wordpress deployment for the public world connectivity .

s-ervice file for -exposing the wordpress alongside

-Step5: Helm upgrade

Hence some new files are added in the helm chart so to affect the changes ,if we again try to install the helm chart it will give us error.

Now we would have to take help of the helm upgrade command:-

#helm upgrade wordpress wordpress/

-

output of upgrade command

Now the required resources will be launched respectively-

res-ources launched successfully

— A-nd thus our helm chart has been successfully set-up and configured.

Result : Accessing wordpress site

wordpress successfully configured

After creating account on this page a login page will appear

Since after login dashboard appears , by this we can conclude that the helm chart has been configured successfully and have proper connection with backend MYSQL.

All the files available at:-

https://github.com/Mayankagarwal007/helm-chart-kubernetes.git

Making our chart more dynamic

For making our chart more dynamic in the previous file the mysql database values are hard coded and fixed and anyone can have their different values.

So for this the concept of values come in place . For taking the values dynamically create a file with by default name values.yaml and define the variable values in this file .-

for example lets take our own chart :-

values.yaml file

And use the value as {{ .Values.variable_name }}

dynamic values fille

Now before installing the chart on can define its own values in the file and the wordpress will be configured accordingly.

--

--