Random Musings

Sporadic thoughts on tech, economics, business, finance and trading

What is a helm chart?

,

A Helm chart can be thought of as a package manager for Kubernetes applications. It simplifies the process of deploying, managing, and configuring applications on a Kubernetes cluster.

Let’s break it down step by step:


1. What is Helm?

  • Helm is a tool that helps you manage Kubernetes applications.
  • It provides a way to define, install, and upgrade even the most complex Kubernetes applications using “charts.”

Think of Helm like a package manager for Kubernetes, similar to how apt is for Ubuntu or yum is for Red Hat Linux.


2. What is a Helm Chart?

A Helm chart is essentially a template-driven package that defines a Kubernetes application. It contains the information necessary to create an instance of a Kubernetes application.

Structure of a Helm Chart

A Helm chart is a directory containing:

  • YAML files: Define the Kubernetes resources and configurations.
  • Templates: Allow you to parameterize values, making deployments reusable and dynamic.
  • Metadata: Contains information about the chart, like its name, version, and dependencies.

Example structure:

my-chart/
├── Chart.yaml         # Metadata about the chart
├── values.yaml        # Default configuration values
├── templates/         # Kubernetes manifest templates
│   ├── deployment.yaml
│   ├── service.yaml
│   └── ingress.yaml
└── charts/            # Subcharts (dependencies)

3. Why Use Helm Charts?

  • Simplifies Deployments: You can package all resources (Deployment, Service, ConfigMaps, etc.) into a single chart.
  • Reusable: You can use the same chart for multiple environments by just changing configuration values.
  • Versioning: Helm charts have versions, so you can roll back to previous versions if needed.
  • Parameterization: You can customize deployments by overriding values.yaml with your own configuration.
  • Dependency Management: Helm allows you to define and manage dependencies between applications.

4. Example: Kubernetes Deployment Without and With Helm

Without Helm:

You’d write multiple YAML files manually:

  • deployment.yaml
  • service.yaml
  • configmap.yaml

Then, apply them to Kubernetes one by one:

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f configmap.yaml

With Helm:

  1. Create a Helm chart with templates for Deployment, Service, etc.
  2. Use a single command to deploy: helm install my-app ./my-chart
  3. Customize with parameters by overriding values.yaml: helm install my-app ./my-chart --set replicaCount=3

5. Key Files in a Helm Chart

  • Chart.yaml: Metadata about the chart, such as name, version, and description. Example: apiVersion: v2 name: my-app description: A Helm chart for my application version: 1.0.0 appVersion: 1.0.0
  • values.yaml: Default configuration values for the chart. Example: replicaCount: 2 image: repository: my-app-image tag: latest service: type: ClusterIP port: 80
  • templates/: Contains the Kubernetes resource templates. Example: # templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Release.Name }}-deployment spec: replicas: {{ .Values.replicaCount }} template: spec: containers: - name: my-app image: {{ .Values.image.repository }}:{{ .Values.image.tag }}

6. Helm Commands

  • Install a chart: helm install my-app ./my-chart
  • Upgrade a chart: helm upgrade my-app ./my-chart --set replicaCount=3
  • Rollback to a previous release: helm rollback my-app 1
  • Uninstall a release: helm uninstall my-app
  • List all releases: helm list

7. Visualizing the Concept

Think of a Helm chart as a “blueprint” for deploying an application. When you install a Helm chart, it renders the templates into Kubernetes manifests (like .yaml files) and applies them to the cluster.


8. Practical Example

Let’s say you want to deploy a simple web app with a Deployment and Service.

Step 1: Create a Helm Chart

helm create my-web-app

Step 2: Customize Values

Edit values.yaml:

replicaCount: 3
image:
  repository: nginx
  tag: stable
service:
  type: LoadBalancer
  port: 80

Step 3: Deploy

Run:

helm install web-app ./my-web-app

Summary

  • A Helm chart is a reusable package that simplifies Kubernetes deployments.
  • It helps you manage complex applications with multiple resources and configurations.
  • By using values.yaml and templates, you can easily customize and manage deployments.