DEV Community

Cover image for Building Your First Helm Chart
Manjunath Kotabal
Manjunath Kotabal

Posted on

1 1 1 1 1

Building Your First Helm Chart

In the previous blog, we discussed the challenges of deploying and managing applications on Kubernetes using raw manifests and Kustomize. We also introduced Helm as a powerful tool to simplify application deployment through templating, packaging, versioning, and dependency management. In this blog, we’ll walk you through setting up your environment for Helm, and guide you through building your very first Helm chart.

In this blog, we’ll explore:

  • Installing Kubernetes with Kind (Kubernetes in Docker).
  • Installing kubectl (Kubernetes command-line tool).
  • Installing Helm.
  • Setting up your first Kubernetes cluster and deploying your first Helm chart.

Prerequisites

Before diving into Helm, you’ll need a few tools installed and configured:

  • Docker: Since we’re using Kind (Kubernetes in Docker), Docker is required.
  • Kubectl: Kubernetes command-line tool for interacting with your cluster.
  • Helm: Helm command-line tool to manage Helm charts.

Step 1: Install Docker

If Docker is not already installed on your machine, download and install Docker from docker.com.

To verify Docker is installed properly:

docker --version
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Kind (Kubernetes in Docker)

Kind is a tool for running Kubernetes clusters in Docker containers, ideal for testing Kubernetes applications locally.

To install Kind:

On macOS (using Homebrew):
brew install kind
Enter fullscreen mode Exit fullscreen mode
On Linux (using curl):
curl -Lo /usr/local/bin/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.17.0/kind-linux-amd64 chmod +x /usr/local/bin/kind
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

kind --version
Enter fullscreen mode Exit fullscreen mode

Step 3: Install kubectl

kubectl is the command-line tool used to interact with your Kubernetes cluster.

To install kubectl:

On macOS (using Homebrew):
brew install kubectl
Enter fullscreen mode Exit fullscreen mode
On Linux (using curl):
curl -LO "https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl" chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

kubectl version --client
Enter fullscreen mode Exit fullscreen mode

Step 4: Install Helm

Helm is the Kubernetes package manager that simplifies deployment and management of applications.

To install Helm:

On macOS (using Homebrew):
brew install helm
Enter fullscreen mode Exit fullscreen mode
On Linux (using curl):
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
Enter fullscreen mode Exit fullscreen mode

Verify the installation:

helm version
Enter fullscreen mode Exit fullscreen mode

Step 5: Create a Kubernetes Cluster with Kind

Now that you have Kind installed, let’s create a local Kubernetes cluster.

Create a Kubernetes Cluster with Kind:

Create a new cluster:
kind create cluster --name my-first-cluster
Enter fullscreen mode Exit fullscreen mode
Check the cluster status: After the cluster is created, you can check the status by running:
kubectl cluster-info --context kind-my-first-cluster
Enter fullscreen mode Exit fullscreen mode

You should now have a running Kubernetes cluster locally, and kubectl will be configured to interact with it.


Step 6: Initialize Helm in Your Cluster

To start using Helm with your Kind cluster, you need to initialize Helm's default configurations and repositories.

Initialize Helm:
helm repo add stable https://charts.helm.sh/stable helm repo update
Enter fullscreen mode Exit fullscreen mode

This will add the default Helm repository containing a collection of publicly available charts.

Verify Helm Initialization:
helm search repo nginx
Enter fullscreen mode Exit fullscreen mode

This command should return a list of available charts from the stable repository, confirming that Helm is set up correctly.

I'll help you convert the content into markdown format. Here's the markdown version:


Step 7: Create Your First Helm Chart

With Helm set up, it’s time to create your first chart!

Create a new Helm chart:

Navigate to the directory where you want to store your Helm charts and run:

helm create my-first-chart
Enter fullscreen mode Exit fullscreen mode

This will generate a folder structure with the following contents:

my-first-chart/
├── Chart.yaml          # Metadata for the chart
├── values.yaml         # Default configuration values
├── charts/             # Dependencies (if any)
├── templates/          # Kubernetes manifest templates
│   ├── deployment.yaml
│   ├── service.yaml
│   └── ...
└── README.md           # Documentation
Enter fullscreen mode Exit fullscreen mode

Chart.yaml: Metadata about the chart (name, version, description).

values.yaml: Default configuration values for your chart.

templates/: A folder containing YAML files for the Kubernetes resources (e.g., Deployment, Service).

Inspect the generated files: In my-first-chart/, you’ll see templates for the most common Kubernetes resources, such as a Deployment and Service.

Chart.yaml: Defines basic chart metadata.

values.yaml: Contains default values, such as the number of replicas and the container image.

templates/deployment.yaml: Defines the Deployment resource, with dynamic values pulled from values.yaml.

templates/service.yaml: Defines the Service resource for exposing your application.

Here’s an example snippet from templates/deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Release.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Enter fullscreen mode Exit fullscreen mode

Edit the values.yaml: Modify values.yaml to adjust configuration parameters like the container image, replicas, etc.

Example:

replicaCount: 2
image: 
  repository: nginx
  tag: stable
Enter fullscreen mode Exit fullscreen mode

Install the Helm Chart: Now, deploy the chart to your cluster using the following command:

helm install my-app ./my-first-chart
Enter fullscreen mode Exit fullscreen mode

Verify the Deployment: To ensure that your deployment was successful, check the status of your pods:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

You should see your my-app pod running.

Checkout my article on adavanced concepts of helm chart: https://dev.to/manjunath_kotabal_3d1e736/advanced-concepts-in-helm-templates-1oo6

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay