Helm Charts: A Simple way to deploy application on Kubernetes

Kubernetes deployment can be manually done but it may take lots of efforts and ton of hours to build and organize yaml file in structured way. Helm charts are one of the best practices for building efficient clusters in Kubernetes.

In this tutorial you will learn step-by-step How to create a Helm chart , set up, and deploy on a web server. Helm charts simplify application deployment on a Kubernetes cluster

Table of content

  1. What is Helm and Helm charts
  2. Prerequisites
  3. Installing Helm on windows machine
  4. Installing Helm on ubuntu machine
  5. Installing Minikube on Ubuntu machine
  6. Creating Helm charts
  7. Configure Helm Chart
  8. Deploy Helm chart
  9. View the Deployed Application
  10. Verify the Pods which we created using Helm chart
  11. Conclusion

What is Helm and Helm charts

Helm is a package manager for kubernetes which makes application deployments and management easier. Helm is a command line tool which allows you to create helm chart .

Helm charts is a collection of templates and setting which defines set of kubernetes resources. In Helm charts we define all the resources which are needed as part of application. Helm charts communicates with kubernetes cluster using REST api.

Working with Helm chart makes the job of deployment or management easier. It also supports versioning.

Prerequisites

  • Docker should be installed on ubuntu machine.
  • kubectl should be installed on ubuntu machine.

Installing Helm on windows machine

To install Helm on Windows machine

  • Now, extract the windows-amd64 zip to the preferred location
  • Now open command prompt and hop to the same location and type helm.exe
  • Now, check the version of helm

Installing Helm on ubuntu machine

To install Helm on ubuntu machine

  • Download the  latest version of Helm package
 wget https://get.helm.sh/helm-v3.4.1-linux-amd64.tar.gz
  •  Unpack the helm package manager
tar xvf helm-v3.4.1-linux-amd64.tar.gz
  • Now move linux-amd64/helm to /usr/local/bin
sudo mv linux-amd64/helm /usr/local/bin
  • Check the version of helm
helm version

Installing Minikube on Ubuntu machine

minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes. Lets Install it.

  • Download and Install the minikube package on ubuntu machine.
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb

sudo dpkg -i minikube_latest_amd64.deb
  • Now start minikube with normal user but not with root user.
minikube start
  • Now verify if minikube is installed properly by running the following commands
minikube status

Creating Helm charts

Before we create Helm chart make sure helm is installed properly. To check run the below command.

which helm
  • Starting a new Helm chart requires one simple command
helm create automate
  • As soon as First-chart is created it will create a folder with the same name containing different files.

Configure Helm Chart

By now Helm chart has been created by using just a single command. But for deploying using Helm chart we would need to configure few files which got generated with helm create command.

  1. Chart.yaml contains details of chart such as name , description , api version to be used , chart version to be deployed etc. You don’t require to update this file .
  1. template directory: Next , most important part of the chart is the template directory which holds all the configurations for your application that will be deployed into the cluster such as ingress.yaml , service.yaml etc . You don’t need any modification in this directory as well.
  1. charts : This folder contains no file initially. Other dependent charts are added here if required. (optional task). Skip this as well.
  1. values.yml: values.yml is a main file which contains all the configuration related to deployments. Customize the values.yml file according to the deployment .
    • replicaCount: is set to 1 that means only 1 pod will come up ( No change required)
    • pullPolicy : Update to Always.
    • nameOverride: automate-app
    • fullnameOverride: automate-chart
    • There are two types of networking options available a) ClusterIP address which exposes service on cluster internal IP and b) NodePort exposes service on each kubernetes node IP address. We will use NodePort here.

Your values.yaml should like something below.

replicaCount: 1

image:
  repository: nginx
  pullPolicy: Always
  # Overrides the image tag whose default is the chart appVersion.
  tag: ""

imagePullSecrets: []
nameOverride: "automate-app"
fullnameOverride: "automate-chart"

serviceAccount:
  # Specifies whether a service account should be created
  create: true
  # Annotations to add to the service account
  annotations: {}
  # The name of the service account to use.
  # If not set and create is true, a name is generated using the fullname template
  name: "automateinfra"

podAnnotations: {}

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
service:
  type: NodePort
  port: 80

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: chart-example.local
      paths: []
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

resources: {}
autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}

Deploy Helm chart

Now that you’ve made the necessary modifications to create a Helm chart, you can deploy it using a Helm command, add a name point to the chart, add a values file, and send it to a namespace:

helm install automate-chart automate/ --values automate/values.yaml
  • Helm install command deploys the app , Now run the both export commands as shown in the helm install command’s output.
export NODE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].nodePort}" services automate-chart)

export NODE_IP=$(kubectl get nodes --namespace default -o jsonpath="{.items[0].status.addresses[0].address}")

View the Deployed Application

  • Run echo command as shown in the output of helm install command.
echo http://$NODE_IP:$NODE_PORT

Verify the Pods which we created using Helm chart

You already saw that application is deployed successfully and we can see that Nginx Page loaded. But to verify from kubernetes end , lets run the following command and verify.

kubectl get nodes

kubectl get pods

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.

Hope you liked this tutorial and it helped you. Please share with your friends.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s