Sling Academy
Home/DevOps/Introduction to Managing Kubernetes Applications with Helm

Introduction to Managing Kubernetes Applications with Helm

Last updated: January 30, 2024

Introduction

As the containerization of applications becomes the norm, orchestrating these containers in production environments has become critical. Kubernetes has emerged as the de facto standard for managing containerized applications at scale. But managing Kubernetes resources and applications can quickly get complicated due to the myriad of configurations. This is where Helm comes to the rescue. Helm is the package manager for Kubernetes that facilitates the deployment and management of applications on Kubernetes clusters. In this tutorial, we’ll walk through the basics of Helm, covering everything from installation to more advanced usage scenarios.

What is Helm?

Helm is an open-source project that provides a way to manage Kubernetes charts—bundles of pre-configured resources that define a set of related Kubernetes resources. Charts simplify the process of defining, installing, and upgrading even the most complex Kubernetes applications.

Installing Helm

First off, you’ll need to have access to a Kubernetes cluster. Once you have your cluster ready, installing Helm is straightforward. You can download the latest version of Helm from the official installation guide. Here’s how you can install Helm using a script on Linux:

curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

For other operating systems or installation methods, you’ll want to follow the appropriate instructions in the documentation. After installation, you can verify Helm is working by running:

helm version

Understanding Helm Charts

Helm Charts are the heart of Helm’s functionality. A chart is essentially a package of pre-configured Kubernetes resources. Charts are contained in a directory with a defined structure, which includes a ‘Chart.yaml’ file that provides metadata about the chart, such as the name, version, and description.

Creating Your First Chart

To create your first Helm chart, you can use the ‘helm create’ command:

helm create my-first-chart

This will generate a directory structure with the necessary files to get started. You can examine the ‘Chart.yaml’ file and modify the default values under the ‘values.yaml’ file to suit your application’s needs.

Installing a Chart

Once you have a chart ready to go, you can install it into your Kubernetes cluster with the ‘helm install’ command. For example:

helm install my-release ./my-first-chart

The ‘my-release’ is the name you give to the set of resources that you’re deploying. The ‘./my-first-chart’ is the path to the chart you want to install.

Upgrading and Rolling Back Releases

To update a release with a newer version of the chart or to change the configuration, you use the ‘helm upgrade’ command:

helm upgrade my-release ./my-first-chart

If you need to rollback to an earlier version of your release, Helm allows you to do so with the ‘helm rollback’ command:

helm rollback my-release 1

Where ‘1’ is the revision number of the release to which you want to rollback.

Chart Repositories

Helm uses chart repositories to share and store charts. You can add a repository with the ‘helm repo add’ command:

helm repo add bitnami https://charts.bitnami.com/bitnami

You can then search for charts in that repository:

helm search repo bitnami

Advanced Chart Configuration

For more advanced chart configurations, you can use templating to dynamically set values according to the deployment environment.

The syntax used in templating is similar to Go templates. This enables you to interpret the ‘values.yaml’ file according to your needs. The following example demonstrates how you can use conditional statements within your templates:

{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: {{ .Release.Name }}-ingress
spec:
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  rules:
    - host: "{{ .Values.ingress.host | default .Release.Name }}.example.com"
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: {{ .Release.Name }}
                port:
                  number: {{ .Values.service.port }}
{{- end }}

This would create an Ingress resource only if the ‘ingress.enabled’ value is set to true in the ‘values.yaml’ file.

Conclusion

In this brief introduction, we’ve covered the essential Helm commands and concepts that will help you manage Kubernetes applications more effectively. With Helm’s robust and dynamic chart system, you can streamline the deployment and management of even the most complex Kubernetes applications, making it an indispensable tool for developers and sysadmins working with Kubernetes.

Next Article: Kubernetes: Creating and Publishing Your Own Helm Charts

Previous Article: Automating Tasks with Kubectl Scripts: A Practical Guide (with Examples)

Series: Kubernetes Tutorials

DevOps

You May Also Like

  • How to reset Ubuntu to factory settings (4 approaches)
  • Making GET requests with cURL: A practical guide (with examples)
  • Git: What is .DS_Store and should you ignore it?
  • NGINX underscores_in_headers: Explained with examples
  • How to use Jenkins CI with private GitHub repositories
  • Terraform: Understanding State and State Files (with Examples)
  • SHA1, SHA256, and SHA512 in Terraform: A Practical Guide
  • CSRF Protection in Jenkins: An In-depth Guide (with examples)
  • Terraform: How to Merge 2 Maps
  • Terraform: How to extract filename/extension from a path
  • JSON encoding/decoding in Terraform: Explained with examples
  • Sorting Lists in Terraform: A Practical Guide
  • Terraform: How to trigger a Lambda function on resource creation
  • How to use Terraform templates
  • Understanding terraform_remote_state data source: Explained with examples
  • Jenkins Authorization: A Practical Guide (with examples)
  • Solving Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap
  • Understanding Artifacts in Jenkins: A Practical Guide (with examples)
  • Using Jenkins with AWS EC2 and S3: A Practical Guide