Helm Chart¶
- Welcome to the
HelmChart hands-on lab! In this tutorial, you’ll learn the essentials ofHelm(version 3), the package manager for Kubernetes. - You’ll build, package, install, and manage applications using
Helmcharts, gaining practical experience with real Kubernetes resources.
What will you learn¶
- What
Helmis and why is it useful Helmchart structure and key files- Common
Helmcommands for managing releases - How to create, pack, install, upgrade, and rollback a
Helmchart - Troubleshooting and best practices
Introduction¶
Helmis the package manager for Kubernetes.- It simplifies the deployment, management, and upgrade of applications on your Kubernetes cluster.
Helmhelps you manage Kubernetes applications by providing a way to define, install, and upgrade complex Kubernetes applications.-
When packing applications as
Helmcharts, you gain a standardized and reusable approach for deploying and managing your services. -
A
Helmchart consists of a few files that define the Kubernetes resources that will be created when the chart is installed. - These files include the:
Chart.yamlfile, which contains metadata about the chart, such as its name and version, and the chart’s dependencies and maintainers.values.yamlfile, which contains the configuration values for the chart.- The
templatesdirectory which contains the Kubernetes resource templates to be used to create the actual resources in the cluster.
Terminology¶
-
Chart- A
Helmpackage is called a chart. - Charts are versioned, shareable packages that contain all the Kubernetes resources needed to run an application.
- A
-
Release- A specific instance of a chart is called a release.
- Each release is a deployed version of a chart, with its own configuration, resources, and revision history.
-
Repository- A collection of charts is stored in a
Helmrepository. Helmcharts can be hosted in public or private repositories for easy sharing and distribution.
- A collection of charts is stored in a
Chart files and folders¶
| Filename/Folder | Description |
|---|---|
Chart.yaml | Contains metadata about the chart, including its name, version, dependencies, and maintainers. |
values.yaml | Defines default configuration values for the chart. Users can override these values during installation. |
templates/ | Directory containing Kubernetes manifest templates written in the Go template language. |
charts/ | Directory containing dependencies of the chart. |
README.md | Documentation for the chart, explaining how to use and configure it. |
codewizard-helm-demo Helm Chart tructure¶
- Chart.yaml # Defines chart metadata and values schema
- values.yaml # Default configuration values
- templates/ # Deployment templates using Go templating language
- deployment.yaml # Deployment manifest template
- service.yaml # Service manifest template
- README.md # Documentation for your chart
Common Helm Commands¶
Here are some of the most common Helm commands you’ll use when working with Helm charts:
| Command | Description |
|---|---|
helm create chart-name | Create a new Helm chart with the specified name. |
helm install release-name chart-path | Install a Helm chart to your Kubernetes cluster. |
helm upgrade release-name chart-path | Upgrade an installed release with a new version of a chart. |
helm uninstall release-name | Uninstall a release from the Kubernetes cluster. |
helm list | List all installed Helm releases in the cluster. |
helm status release-name | Show the status of a deployed Helm release. |
helm rollback release-name revision | Rollback a release to a previous revision. |
helm get all release-name | Retrieve all information about a deployed release (e.g., templates, values). |
helm show values chart-name | Show the default values of a Helm chart. |
helm template chart-name | Generate the output of the Helm chart. |
helm lint chart-path | This command takes a path to a chart and runs a series of tests to verify that the chart is well-formed. |
helm history chart-name | This command takes a path to a chart and runs a series of tests to verify that the chart is well-formed. |
Lab¶
Step 01 - Installing Helm¶
-
Before you can use the
codewizard-helm-demochart, you’ll need to installHelmon your local machine. -
Helminstall methods by OS:
| OS | Command |
|---|---|
| Linux | curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 \| bash |
| MacOS | brew install helm |
| Windows (via Chocolatey) | choco install kubernetes-helm |
Verify Installation¶
- To confirm that
Helmis installed correctly, run:
$ helm version
## Expected output
version.BuildInfo{Version:"xx", GitCommit:"xx", GitTreeState:"clean", GoVersion:"xx"}
Step 02 - Creating our Helm chart¶
- Creating our custom
codewizard-helm-demoHelmchart -
The custom
codewizard-helm-demoHelmchart is build upon the following K8S resources:- ConfigMap
- Deployment
- Service
-
As mentioned above, we will also have the following
Helmresources:- Chart.yaml
- values.yaml
- templates/_helpers.tpl
Create a New Chart¶
- First, we need to create a
Helmchart using thehelm createcommand. - This command will generate the necessary file structure for your new chart.
What is the result of this command?
Examine the chart structure!
Navigate to the Chart Directory¶
Write the chart content¶
- Copy the content of the chart folder (in this lab) to the chart directory (overwriting the files).
Step 03 - Pack the chart¶
- After we have created or customized our chart, we need to pack it as
.tgzfile, which can then be shared or installed.
helm package¶
Helm Package
helm package packages a chart into a versioned chart archive file.
If a path is given, this will “look” at that path for a chart which must contain a Chart.yaml file and then pack that directory.
- This command will create a file called
codewizard-helm-demo-<version>.tgzinside your current directory.
Step 04 - Validate the chart content¶
helm template¶
Helmallows you to generate the Kubernetes manifests based on the templates and values files without actually installing the chart.- This is useful to preview what the generated resources will look like:
helm template codewizard-helm-demo
## This will output the rendered Kubernetes manifests to your terminal
Step 05 - Install the chart¶
- Install the
codewizard-helm-demochart into Kubernetes cluster
The helm install command¶
- This command installs a chart archive.
- The install argument must be a chart reference, a path to a packed chart, a path to an unpacked chart directory or a URL.
- To override values in a chart, use:
--values- pass in a file--set- pass configuration from the command line
Step 06 - Verify the installation¶
- Examine newly created
Helmchart release, and all cluster created resources:
Step 07 - Test the service¶
- Perform an
HTTP GETrequest, send it to the newly created cluster service. - Confirm that the response contains the
CodeWizard Helm Demomessage passed from thevalues.yamlfile.
kubectl run busybox \
--image=busybox \
--rm \
-it \
--restart=Never \
-- /bin/sh -c "wget -qO- http://codewizard-helm-demo.codewizard.svc.cluster.local"
### Output:
CodeWizard Helm Demo
Step 08 - Upgrade the release to newer version¶
- Perform a Helm upgrade on the
codewizard-helm-demorelease:
# upgrade and pass a different message than the one from the default values
# Use the --set to pass the desired value
helm upgrade \
codewizard-helm-demo \
codewizard-helm-demo-0.1.0.tgz \
--set nginx.conf.message="Helm Rocks"
Step 09 - Check the upgrade¶
- Perform another
HTTP GETrequest. - Confirm that the response now has the updated message
Helm Rocks:
kubectl run busybox \
--image=busybox \
--rm \
-it \
--restart=Never \
-- /bin/sh -c "wget -qO- http://codewizard-helm-demo.codewizard.svc.cluster.local"
### Output:
Helm Rocks
Step 10 - History¶
- Examine the
codewizard-helm-demorelease history
helm history¶
helm historyprints historical revisions for a given release.- A default maximum of 256 revisions will be returned.
$ helm history codewizard-helm-demo
### Sample output
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 ... superseded codewizard-helm-demo-0.1.0 1.19.7 Install complete
2 ... deployed codewizard-helm-demo-0.1.0 1.19.7 Upgrade complete
Step 11 - Rollback¶
helm rollback¶
- Rollback the
codewizard-helm-demorelease to previous version:
- Check again to verify that you get the original message!
Finalize & Cleanup¶
- To remove all resources created by this lab, uninstall the
codewizard-helm-demorelease:
- (Optional) If you have created a dedicated namespace for this lab, you can delete it by runniung:
Troubleshooting¶
- Helm not found:
Make sure Helm is installed and available in your PATH. Run the following to verify:
- Pods not starting:
Check pod status and logs by running the following commands:
kubectl get pods -n codewizard
kubectl describe pod <pod-name> -n codewizard
kubectl logs <pod-name> -n codewizard
- Service not reachable:
Ensure the service and pods are running by running the following commands:
- Values not updated after upgrade:
Double-check your --set or --values flags and confirm the upgrade by running:
Next Steps¶
- Try creating your own
Helmchart for a different application. - Explore
Helmchart repositories like Artifact Hub. - Learn about advanced
Helmfeatures, such as: dependencies, hooks, and chart testing. - Integrate
Helmwith CI/CD pipelines for automated deployments. - Read more in the official Helm documentation.