Contents

Helm

Helm is an open source package manager for Kubernetes. It provides the ability to provide, share, and use software built for Kubernetes.

Key concepts

  • A Chart is a Helm package.
    • It contains all of the resource definitions necessary to run an application, tool, or service inside of a Kubernetes cluster.
    • Think of it like the Kubernetes equivalent of a Homebrew formula, an Apt dpkg, or a Yum RPM file.
    • It uses a templating engine to make the YAML files dynamic.
  • A Repository is the place where charts can be collected and shared.
    • It’s like the Fedora Package Database, but for Kubernetes packages.
  • A Release is an instance of a chart running in a Kubernetes cluster.
    • One chart can often be installed many times into the same cluster. And each time it is installed, a new release is created.
    • Consider a MySQL chart. If you want two databases running in your cluster, you can install that chart twice. Each one will have its own release, which will in turn have its own release name.

Benefits

  • Version Control: A history of releases is maintained by Helm. In the event of a deployment failure, a previous stable state can be instantly restored by executing a helm rollback.
  • Reusability: The manual creation of YAML for common infrastructure tools, such as Postgres, Redis, or Prometheus, is rendered unnecessary. Public charts can be used to fulfill these requirements.
  • Environment Management: A single chart can be utilized across multiple environments. Environment-specific logic is managed through the application of distinct values files, such as values-dev.yaml and values-prod.yaml.

Templating Logic

Standard YAML:

metadata:
name: my-app-service

Helm Template YAML:

metadata:
name: {{ .Release.Name }}-service

When you deploy, Helm replaces {{ .Release.Name }} with the actual name you give your deployment.

Common commands

CommandAction
helm install [name] [chart]Deploy a new application instance.
helm upgrade [name] [chart]Update an existing application.
helm rollback [name] [revision]Revert to a previous version.
helm listSee all running releases in the namespace.
helm uninstall [name]Remove the application and all its resources.

Example

  1. Deployment Template (templates/deployment.yaml)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-deployment
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    spec:
      containers:
        # Main Java Application
        - name: java-app
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          ports:
            - containerPort: {{ .Values.service.port }}
  1. Configuration File (values.yaml)
replicaCount: 3

image:
  repository: my-java-app
  tag: "2.1.0"
  pullPolicy: IfNotPresent

service:
  type: ClusterIP
  port: 8080
  1. Linting: helm lint ./my-java-app
  2. Dry Run: helm install my-javaservice ./my-java-app --dry-run --debug
  3. Installation of chart to cluster: helm install my-java-app-prod ./my-java-app -f values.yaml
  4. Verification:
helm status revenue-prod
kubectl get pods -l app=my-javaservice
  1. Upgrade after any changes to values.yaml: helm upgrade revenue-prod ./my-java-app-chart -f values.yaml
  2. Rollback: helm rollback my-java-app-prod 1

References