Helm is a package manager for Kubernetes applications. It simplifies the process of defining, installing, and upgrading even the most complex Kubernetes applications. Helm uses a packaging format called "charts," which are a collection of pre-configured Kubernetes resources.
Here are the key components and concepts associated with Helm:
Concept
Description
Helm
A package manager for Kubernetes applications that simplifies application installation and management.
Charts
Collections of pre-configured Kubernetes resources defining how to deploy specific applications.
Templates
Helm chart components that include Kubernetes resource manifests with placeholders for customization.
Values
Parameters allowing customization of Helm charts during installation without modifying the templates.
Release
An instance of a Helm chart installed in a Kubernetes cluster, created with specific values.
Repository
Storage for Helm charts, which can be public or private and are typically hosted on various services.
Dependency Management
Helm supports specifying and managing dependencies between charts, enabling complex application composition.
Here's the workflow for using Helm presented as a table:
Step
Description
1. Create or Obtain a Chart
You can either create your own Helm charts for your applications or obtain pre-made charts from public or private repositories. Many popular applications and services offer Helm charts.
2. Customize Values
Customize the configuration of a Helm chart by providing custom values. These values override the defaults defined in the chart.
3. Install the Chart
Use the Helm CLI to install the chart into your Kubernetes cluster. Specify the release name and values file (if needed). Helm will create the necessary Kubernetes resources based on the chart and values.
4. Upgrade and Rollback
Helm provides tools to easily upgrade a release to a new version of the chart or roll back to a previous version if issues arise during deployment or updates.
5. Uninstall
When you're finished with an application, use Helm to uninstall the release. Helm will remove all associated resources, ensuring a clean removal.
In the Minikube Sample Project, we already knew the way to deploy a simple Spring Boot application and MongoDB with Kubernetes. However, what will we do if we need to clone this application setup to multiple environment like DEV, TEST, STG, etc. So, we have to create multiple yaml files for every environment and we have to apply every file manually right?. It really take many efforts and time to operate multiple environments and it makes us also hard to control all environments. So Helm will be the solution for us.
Imagine that we will have some template files which define the structure for deploying an application on Kubernetes as we did in Minikube Sample Project. However, we can map values from value files into these template files using Helm. so it means with a template set we can use it to deploy multi environments because every environment we will map with a value file. Let's see the image below.
Used to include and manage subcharts, which are nested Helm charts that can be used within the parent chart to modularize and reuse components.
Chart.yaml
Metadata file for the Helm chart.
Contains metadata about the chart, including its name, version, description, and other details. This information is used for tracking, searching, and managing chart releases.
templates/
Folder for Kubernetes resource templates.
Contains YAML templates for Kubernetes resource manifests. These templates often include placeholders for values that can be customized during chart installation. Helm uses these templates to generate actual manifests.
values.yaml
File for default configuration values.
Specifies default configuration values for the chart. Users can override these defaults by providing their own values.yaml file during chart installation. This allows for easy customization without altering the chart's templates.
In this example, we just focus on creating resource templates and configuration value files because we just to deploy a simple application on multiple environments.
We can see that the values of name, mongo-url and mongo-port are hard-coded. So we can't use this file for multiple environments because we can't change the values.
Now, let's update the content of the mongo-config.yaml in the templates folder as below.
Now, the values of values of name, mongo-url and mongo-port can be mapped from a values file by using the template expression, so with multiple environments, we just need to define multiple values file.
The template expression can be explained as below. Ex: we have {{ .Values.mongo.config.name }}
{{ ... }}: Double curly braces denote the start and end of a template expression. Everything inside these braces is evaluated as a template.
.: The period . represents the current context within the template. In the context of a Helm chart, this often refers to the root context, which includes values, templates, and other chart-related data.
Values: In Helm charts, .Values is a special object that contains all the values defined in the values.yaml file or provided by the user during chart installation. It's a way to access and interpolate these values into templates.
mongo: This is a key within the .Values object. It indicates that you are accessing a value nested under the mongo key.
config: Similarly, config is another key nested within the mongo key.
name: Finally, name is the specific value being accessed under the config key.
Then in the values.yaml we will have the configuration for {{ .Values.mongo.config.name }} as below:
values.yaml
123
mongo:config:name:mongo-config-dev
With this approach, we can make any field in the template to be configurable and in the values.yaml file we can also structure the configuration as we expect.
So, we will apply this way for other resource template files. Let's update resource templates for MongoDB with the following yaml files as below.
Now, we have just finished creating deployment templates and repair configurations for DEV deployment in the values.yaml file. So, to repair deployment for TEST environment, we just need to create another values file, let's call it as values-test.yaml with the configuration as below.
Specifies a values file to customize the chart's configuration.
my-sample-dev
Names the release created by the installation.
helm/sample/
Indicates the path to the Helm chart to be installed.
After executing the command above for deploying DEV environment, we can see the results below.
As you can see, in the values.yaml which is used for DEV deployment, we configured exporting node port 31000, so we can check the DEV application through some api calls with postman.
The ip address in the api is the ip address of minikube instance, we can get it by running the command.
1
minikubeip
Now, to deploy TEST environment, we also will run the command as we did for DEV with different values file and helm chart release name.
As you can see, in the values-test.yaml which is used for TEST deployment, we configured exporting node port 32000, so we can check the TEST application through some api calls with postman.
So we have finished deployment for 2 environments DEV and TEST by using Helm. We can see that Helm helps us saving time a lots and maybe in future if we need to create new environment, we just need to create new values file and update the configuration values.
Last but not least, if we have changed some values in the values.yaml or values-test.yaml. We can use the command below to update the helm chart.