Back

Using HELM to deploy applications to Kubernetes clusters


Prerequisite:

  1. 1. A running kubernetes cluster like EKS etc.
  2. 2. Manifest files(if any)

What is Helm?

Helm is a package manager for Kubernetes, an open-source container orchestration system. It helps you manage and deploy applications on a Kubernetes cluster by providing you with tools to define, install, and upgrade your applications.

Helm uses "charts" to package and deploy applications. A chart is a collection of files that describe a related set of Kubernetes resources. You can use Helm to install, upgrade, and delete charts, as well as manage the dependencies between them. Overall, Helm is a useful tool for managing and deploying applications on Kubernetes clusters, as it provides a simple and organized way to manage complex application deployments.

What is Helm chart?

A Helm chart is a collection of files that describe a related set of Kubernetes resources. Charts are used to package and deploy applications on a Kubernetes cluster using Helm.

Charts can define dependencies between resources, allowing Helm to manage complex application deployments.

Charts are written in YAML and can include templates for Kubernetes resource configuration files. Helm provides a repository of charts that you can use to find and install pre-packaged applications, as well as tools to create and publish your own charts.

It can be considered as a bundle with one or more kubernetes manifests Helm charts can contain child charts and dependent charts Versioning of manifests can also be done just like npm

What is values.yaml in helm chart?

In a Helm chart, the values.yaml file is a configuration file that contains default values for the chart's parameters. When you install or upgrade a chart, you can override these default values by providing your own values in a separate YAML file or by using the --set flag with the Helm command.

The values.yaml file is a simple YAML document that contains a mapping of parameter names to their default values. For example, a chart might define a parameter for the name of a deployment, and the values.yaml file might set the default value for that parameter to "my-app".

Here is an example values.yaml file for a chart:

replicaCount: 1

image:
  repository: nginx
  tag: stable
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 80

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

resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 100m
    memory: 128Mi

nodeSelector: {}


tolerations: []

affinity: {}

In this example, the values.yaml file defines several parameters, including replicaCount, image, service, and ingress, among others.

When you install or upgrade this chart, you can override these default values by providing your own values in a separate YAML file or using the --set flag with the Helm command. For example, you might override the default replicaCount value of 1 by specifying a new value of 2 using the --set flag:

helm install mychart --set replicaCount=2

This would install the chart with a replica count of 2, rather than the default value of 1 specified in the values.yaml file.

Example of –set flag:

helm upgrade --install --create-namespace myChart ./path/to/my/chart \
  --set image.tag=v2.0.0 \
  --set env=dev \
  --set environment.FROM_ADDRESS="test@test.com" \
  --set environment.FROM_NAME="Gourav thakur"

Installing Helm on Ubuntu

Quick note: When installing Helm, make sure you're installing version 3. version 2 still works, but it needs a server-side component called Tiller, which ties your helm installation to a single cluster. Helm 3 removed this need with the addition of several CRDs, but it's not supported in all Kubernetes versions.

Step 1: wget https://get.helm.sh/helm-v3.4.1-linux-amd64.tar.gz

Step 2: tar -xvf helm-v3.4.1-linux-amd64.tar.gz

Step 3: sudo mv linux-amd64/helm /usr/local/bin/

Step 4: sudo usermod -a -G helm $USER

Step 5: helm version

Creating a helm chart

helm create <chart name> :it will create a directory filled with files and other directories. Those files are required for Helm to create a chart. For example: helm create myhelmchart

Using the ls command, list the chart structure: ls <chart name>

Configure Helm Chart Image Pull Policy

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

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.

Change the image pullPolicy from IfNotPresent to Always: Like this:

image:
  repository: nginx
  tag: stable
  pullPolicy: Always

Helm Chart Name Override

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

For e.g Change: nameOverride: “ ” to nameOverride: “myhelmchart” fullnameOverride: “ ” to fullnameOverride: “myhelmchart”

Overriding the Helm chart name ensures configuration files also change.

Add nameOverride and fullnameOverride to values.yaml:

imagePullSecrets: []
nameOverride: "my-first-helm"
fullnameOverride: "my-first-helm"

Change service type to from ClusterIP to LoadBalancer:

service:
  type: LoadBalancer
  port: 80

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: Specify the name of the service account:
    serviceAccount:
    Create: true
    Annotation: {}
    name: my-first-helm-service-name
    

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 myhelmchart myhelmchart/ --values myhelmchart/values.yaml

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:

View the Deployed Application

echo http://$NODE_IP:$NODE_PORT

Send logs from EKS with Promtail to Grafana

Promtail is used to send logs to loki instance and grafana will be used for analytics and visualization...

How to Install Redis on Ubuntu 18.04

Redis delivers sub-millisecond response times enabling millions of requests per second for real-time applications in Gaming, Ad-Tech, Financial Services, Healthcare, and IoT. It supports data structures such as strings, hashes, lists, sets, sorted sets...

Get in touch_

Or just write me a letter here_