DEV Community

Hassan BOLAJRAF
Hassan BOLAJRAF

Posted on

Kubernetes | Helm Commands with YAML File Examples

Note
You can check other posts on my personal website: https://hbolajraf.net

Helm Commands with YAML File Examples

Helm is a powerful package manager for Kubernetes that simplifies the deployment and management of containerized applications. In this guide, we'll explore some common Helm commands and provide detailed examples of Helm Chart YAML files.

Helm Commands

Initialize a Helm Chart

To create a new Helm chart, you can use the following command:

helm create mychart
Enter fullscreen mode Exit fullscreen mode

This command generates the necessary directory structure and files for your chart.

Installing a Chart

To install a Helm chart, you can use the following command:

helm install my-release ./mychart
Enter fullscreen mode Exit fullscreen mode

Here, my-release is the name you give to the release, and ./mychart is the path to your Helm chart.

Upgrading a Chart

To upgrade a Helm release, you can use the following command:

helm upgrade my-release ./mychart
Enter fullscreen mode Exit fullscreen mode

This command is used to apply changes to a deployed release.

Uninstalling a Chart

To uninstall a Helm release, you can use the following command:

helm uninstall my-release
Enter fullscreen mode Exit fullscreen mode

This command removes the release and associated resources.

Helm Chart YAML Examples

Chart.yaml

The Chart.yaml file provides metadata about your Helm chart. Here's an example:

apiVersion: v2
name: mychart
description: A Helm chart for my application
version: 0.1.0
appVersion: 1.0.0
Enter fullscreen mode Exit fullscreen mode

values.yaml

The values.yaml file contains configuration values for your Helm chart. Here's an example:

replicaCount: 1
image:
  repository: nginx
  tag: stable
  pullPolicy: IfNotPresent
service:
  name: mychart-service
  type: ClusterIP
  port: 80
Enter fullscreen mode Exit fullscreen mode

Deployment.yaml

The Deployment.yaml file is part of your Helm chart's templates and defines a Kubernetes Deployment. Here's an example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mychart.fullname"  }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          ports:
            - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

Service.yaml

The Service.yaml file defines a Kubernetes Service for your application. Here's an example:

apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.service.name }}
spec:
  selector:
    app: {{ include "mychart.name"  }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: 80
Enter fullscreen mode Exit fullscreen mode

What Next?

These are just a few examples of Helm commands and YAML files used in Helm charts. Helm makes it easier to package, deploy, and manage Kubernetes applications, allowing you to define and version your application configurations in a structured way.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay