Featured image

Comprehensive Guide to Helm Charts: In-Depth Package Management for Kubernetes

Helm charts have become the de facto standard for packaging, configuring, and deploying applications on Kubernetes. As Kubernetes adoption grows, managing complex applications with multiple microservices demands an efficient package management system. Helm offers a powerful, flexible, and repeatable way to deploy Kubernetes resources, enabling teams to version, share, and manage applications with ease.

This comprehensive article dives deep into Helm charts, focusing on practical usage, best practices, and real-world scenarios. By the end, you will have a thorough understanding of how to create, customize, package, and distribute Helm charts effectively.


What Are Helm Charts?

Helm charts are collections of YAML templates and configurations that define Kubernetes resources. They allow you to parameterize Kubernetes manifests, making deployments reusable and configurable across different environments.

Key benefits of Helm charts:

  • Simplification: Reduces complexity by abstracting Kubernetes manifests into reusable templates.
  • Versioning and Rollbacks: Helm manages chart versions and supports rolling back to previous releases.
  • Configuration Management: Values files enable environment-specific configurations without modifying templates.
  • Sharing and Distribution: Charts can be packaged and hosted on Helm repositories for easy consumption.

Real-World Scenario: Managing Payments and Shipping Services

Imagine you are a DevOps engineer at an e-commerce company tasked with managing two core services: Payments and Shipping. Each service runs in Kubernetes pods and requires independent deployment and updates.

Using Helm charts, you can package the deployments for Payments and Shipping services separately, customize configurations per environment, and host these charts in a Helm repository for streamlined deployments.

This scenario will guide you through creating and managing Helm charts for these services using a dummy BusyBox container to simulate workload.


Prerequisites

Before starting, ensure the following are set up:

  • Helm CLI: Installed on your local machine. You can install Helm from https://helm.sh/docs/intro/install/.
  • Kubernetes Cluster: A running cluster such as Minikube, kind, or a cloud provider cluster.
  • kubectl: Configured to interact with your Kubernetes cluster.
  • GitHub Account: To host your Helm repository via GitHub Pages.

Step 1: Creating Helm Charts

Start by creating a directory structure that will hold your Helm charts for Payments and Shipping:

mkdir -p helm-repo/{payments,shipping}
cd helm-repo

Use Helm to scaffold the basic chart structure for each service:

helm create payments
helm create shipping

This command generates directories with sample charts including templates, default values, and metadata files.


Step 2: Customizing Helm Charts

By default, the generated charts include example deployments. We will modify these to use the BusyBox image and a simple command simulating service behavior.

Deployment Template

The deployment manifest is located at templates/deployment.yaml. Update it to the following to use BusyBox and echo a service-specific message:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-{{ .Chart.Name }}
  labels:
    app: {{ .Chart.Name }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: {{ .Chart.Name }}
  template:
    metadata:
      labels:
        app: {{ .Chart.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
          command: ['sh', '-c', 'echo {{ .Values.appMessage }}; sleep 3600']
          imagePullPolicy: {{ .Values.image.pullPolicy }}

This template uses Helm placeholders to inject values dynamically.

Payments Chart Customization

Edit payments/values.yaml:

image:
  repository: busybox
  tag: latest
  pullPolicy: IfNotPresent
appMessage: "Payments Service"

The deployment template will use these values to configure the container image and command.

Shipping Chart Customization

Similarly, edit shipping/values.yaml:

image:
  repository: busybox
  tag: latest
  pullPolicy: IfNotPresent
appMessage: "Shipping Service"

By parameterizing the application message, the same template can be reused for different services.


Step 3: Packaging Charts

Once customized, package each chart into a versioned .tgz archive:

helm package payments
helm package shipping

This creates payments-0.1.0.tgz and shipping-0.1.0.tgz files.

Next, generate an index file that Helm clients use to discover chart metadata:

helm repo index .

The index.yaml file lists all charts with their versions and download URLs.


Step 4: Hosting Your Helm Repository on GitHub Pages

To share your charts, you can create a Helm repository hosted on GitHub Pages.

Create GitHub Repo

  • Name your repository, for example, helm-repo.

Initialize Git & Push

git init
git remote add origin https://github.com/yourusername/helm-repo.git
git add .
git commit -m "Add payments and shipping charts"
git push -u origin main

Enable GitHub Pages

  • Navigate to your GitHub repository settings.
  • Under “Pages”, set the source branch to main and root directory /.
  • GitHub will publish your repo at https://yourusername.github.io/helm-repo/.

Your index.yaml and packaged charts are now accessible via this URL.


Step 5: Using Your Hosted Helm Repo

On any machine with Helm installed, add your repo:

helm repo add myrepo https://yourusername.github.io/helm-repo
helm repo update

Search for available charts:

helm search repo myrepo

Install the Payments service chart:

helm install payments-service myrepo/payments

Verify your deployments using:

kubectl get deployments
kubectl get pods

Best Practices for Helm Chart Development

  • Parameterize Configurations: Use values.yaml to expose configurable parameters, avoiding hardcoding.
  • Use Meaningful Naming: Chart and release names should be descriptive to avoid conflicts.
  • Version Your Charts: Follow semantic versioning for charts to keep track of changes.
  • Test Your Charts: Use helm template and tools like helm unittest to validate templates.
  • Keep Charts Lightweight: Avoid bloated charts by including only necessary Kubernetes resources.
  • Document Your Charts: Provide README files with usage instructions and configurable values.

Advanced Tips

  • Dependency Management: Use requirements.yaml or Helm 3’s Chart.yaml to declare dependencies for complex applications.
  • Chart Repositories: Consider dedicated Helm repository managers like ChartMuseum or Harbor for enterprise environments.
  • CI/CD Integration: Automate chart packaging and publishing using pipelines.
  • Security Considerations: Scan charts for vulnerabilities and avoid embedding sensitive data.

Conclusion

Helm charts empower Kubernetes users to manage complex deployments with ease and consistency. By packaging microservices like Payments and Shipping into Helm charts, teams can streamline deployment workflows, promote reusability, and maintain environment-specific configurations effortlessly.

This guide provided an in-depth, practical walkthrough of creating, customizing, packaging, and publishing Helm charts, along with best practices to ensure your charts are maintainable and scalable.

Start leveraging Helm charts today to bring order and efficiency to your Kubernetes application deployments.


Additional Resources


Author: Joseph Perez