Packaging Kubernetes Applications using Helm

One of the simplest ways to package Kubernetes applications for deployment is by creating a helm chart. For this blog, I have shared a helm chart that deploys Jenkins on a Pod in a Kubernetes Cluster, you can find my example helm chart and package in my GitHub Repository.

To create a helm chart, run

helm create <chart_name>

Running the above command will create a directory called <chart_name> with the following structure:

chart_name
|-- Chart.yaml
|-- charts
|-- templates
|   |-- NOTES.txt
|   |-- _helpers.tpl
|   |-- deployment.yaml
|   |-- ingress.yaml
|   |-- service.yaml
|   |-- tests
|   |   |-- test-connection.yaml
|-- values.yaml

The most important parts of the chart are the values.yaml file and the templates sub-directory. The templates directory is where the YAML definitions for the objects that make up your Kubernetes application reside. You could either start a new chart and create your definitions using the included templates or you can replace the template files with your existing YAML files for your deployment, service, etc. The values.yaml file is used to set default configurations/variables that can be modified during deployment. Once you’ve added the necessary files to the templates directory and updated your values.yaml file, you can package the chart and install it.

As a best practice, it’s important to lint your helm chart to ensure there are no errors or malformed yaml:

helm lint ./<chart_name>

Once your chart is successfully linted with no errors, you can test that your application is deployed as expected by running the helm install command to build locally:

helm install --name <name_of_application/deployment> ./<chart_name>
#To set a variable on the command line rather than using the default in the `values.yaml` file, you can run:
helm install --name <name_of_application/deployment> ./<chart_name> --set <variable_name>=<value>

Once you are satisfied with the deployment, you can package the chart for sharing/future deployments

helm package ./<chart_name>

Helm will create a tarball of your chart in the same working directory called <chart_name-version.tgz> that can be used to install your application. The name and version helm uses as a naming convention for the tarball includes information derived from your chart.yaml file.

To install using the packaged helm chart, you would run:

helm install --name <name_of_application/deployment> <chart_name-version.tgz>

*Cover Images from medium.com