03 February, 2024

Create a simple Helm chart with Example.

Helm Charts:

The Helm package manager for Kubernetes.

Tiller is the server portion of helm and you need to install it in you Kubernetes cluster using the below command.

Command: helm init

First you need to Download helm from the below link based on operating system:

https://github.com/helm/helm/releases

 

Set path in windows to run the helm commands through CLI:

Copy full path where you extracted downloaded file from above link:


Goto environmental variable and select path and click edit :


Click new and add the helm path:


Now you can restart the system and goto command prompt check with helm command:


 

Now tiller is in your cluster then net you need to role bind the cluster admin permissions to deploy the services.

 


Create the helm chart:


helm create <CHART-NAME>

helm create basechart

Observation:

1. It will create a Helm Chart template

2. We can call it like a helm chart created from a default starter chart

Inside the directory there is deployment, service, ingress manifests in the templates folder.


Chart.yaml is the file which contains the information about the metadata(application,library etc..) and basic API information about the Chart. Following is a sample file of helm Chart.yaml

Example:


 


Values.yaml:

Values.yaml file will have the values like Image parameters, Dependencies, Configurations. This will always override the values which are defined in the chart file.  Here are some samples.

We can also pass the values to the commands from external files

 Examples: helm install -f path/to/myvals.yaml  ./mychart

                    helm upgrade --install my-airflow apache-airflow/airflow  --values .\values.yaml


.helmignore: contains pattern to ignore when packaging helm charts.

 

Templates Folder.

We have a template/ folder created under the same directory when you execute the helm create command. This particular folder will have the default folders as mentioned below.

  • NOTES.txt
  • deployment.yaml
  • service.yaml
  • _helper.tpl

NOTE.txt file is like the document file which will be displayed when you run the helm install command.

Deployment.yaml will have the manifest to create Kubernetes Deployment objects.

Service.yaml is the file which will have the manifest for creating a service endpoint you’re your deployments.

_helpers.tpl file will have the re-usable component throughout the chart.

Charts/ folder:

So, charts/ folder will carry any of the charts that the user is going to create. We can say it as dependencies of the main chart.yaml file. Say for example, If we are going to create mysql DB using Kubernetes and we are going to deploy the same using the helm charts. So, we can create a directory structure as mentioned below.

Example structure:

Charts.yaml

..

..

Charts/

    mysql/

        Chart.yaml

 

The Chart.yaml file defined inside the subdirectories is called as sub chart. And every file can fetch its own values.yaml.

 

How to create a Template:

As the first step of creating the Helm chart, we will create a ConfigMap Template, we need to create a template file called configmaps.yaml file. This file should contain the following lines.

apiVersion: v1

kind: ConfigMap

metadata:

  name: mychart-configmap

data:

  myvalue: "Sample Config Map"

 

 

Basically, this file will simply store the information that will help Kubernetes to have its object to store configuration data. In this file, myvalue: “sample Config Map” is the key value pair that will be sent to the Kubernetes.

To apply the above configuration to the cluster, we need to run the following command.

$ helm install helm-demo-configmap ./my-chart

So, when you check the Kubernetes cluster, you can see the ConfigMap created by using the Helm chart template that we created now.

 

Tests folder:

We write tests we validate that validate our chart works as expected when it is installed.

These tests also help the chart consumer understand what this helm chart supposed to do.

Verify if application is up and running after deploying the chart:

     Command: helm test release-name

 

Helm Variables:

Variables are assigned with a special assignment operator :=

How we can define a variable?


How we can reference a variable?


Below commands are used to perform the actions  uninstall, status, history, rollback:

Helm status release-name:

Helm uninstall release-name 

helm install . --dry-run –debug

helm upgrade what-the-helm .

helm history what-the-helm

helm rollback what-the-helm 1

helm chart folder structure:

Helm useful commands:

 

Airflow installation through helm:

# add helm repo

helm repo add apache-airflow https://airflow.apache.org

# get project

PROJECT=$(oc project -q)

 

# get openshift uid/gid range

CHART_UID=$(oc get project sbipoc-dev -o jsonpath="{['metadata.annotations.openshift\.io/sa\.scc\.uid-range']}" | sed "s@/.*@@")

CHART_GID=$(oc get project sbipoc-dev -o jsonpath="{['metadata.annotations.openshift\.io/sa\.scc\.supplemental-groups']}" | sed "s@/.*@@")

 

echo "UID/GID: ${CHART_UID}/${CHART_GID}"

 

# copy and edit values.yaml

cp example_values.yaml values.yaml

 

# edit values.yaml

 

# install via helm

Install the apache airflow with custom values.yaml file.

helm upgrade \

    --install airflow apache-airflow/airflow \

    --namespace ${PROJECT} \

    --version 1.10.0 \

    --set uid=${CHART_UID} \

    --set gid=${CHART_GID} \

    --set redis.securityContext.runAsUser=${CHART_UID} \

    --set postgresql.volumePermissions.enabled=true

     --values ./values.yaml

 

 

 

Create Routes:

# create route for airflow

We need a one route to host the application outside world. Please use below command to create a route for service.

oc create route edge \

    --service=airflow-webserver \

    --insecure-policy=Redirect \

    --port=8080

 

# create route for airflow flower

oc create route edge \

    --service=airflow-flower \

    --insecure-policy=Redirect \

    --port=5555

 

# confirm routes

oc get routes-à this command helps to get the route url to access the webpage.

 

 

https://artifacthub.io/packages/helm/airflow-helm/airflow/8.5.1

 

 

 

 

 


No comments:

Post a Comment