HELM Cheatsheet

HELM Cheatsheet

Photo by Loik Marras on Unsplash

Three Big Concepts

A Chart is a helm package.

A Repo is a place where these charts get collected and shared.

A Release is an instance of a chart running in a Kubernetes cluster.

Directory Structure

wordpress/
  Chart.yaml      # A YAML file containing information about the chart
  LICENSE         # OPTIONAL: A plain text file containing the license for the chart
  README.md       # OPTIONAL: A human-readable README file
  values.yaml     # The default configuration values for this chart
  values.schema.json  # OPTIONAL: A JSON Schema for imposing a structure on the values.yaml file
  charts/         # A directory containing any charts upon which this chart depends.
  crds/           # Custom Resource Definitions
  templates/      # A directory of templates that, when combined with values,
                  # will generate valid Kubernetes manifest files.
  templates/NOTES.txt # OPTIONAL: A plain text file containing short usage notes

Manage Repo

helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo list
helm repo remove <repo-name>
helm repo update
helm repo remove
helm repo index

Manage Chart

#create helm chart
helm create <chart-name>

#Searching
helm search repo <chart-name>
helm search repo <repo-name> #to see all the charts in a repo
helm search hub <chart-name> #to search on artifcathub

#See information on charts
helm show/inspect all/chart/crds/readme/values <chart-name>
helm show all bitnami/wordpress
helm show values bitnami/wordpress
helm show chart bitnami/wordpress
helm show readme bitnami/wordpress

#generate the manifest from chart
helm template <chart-name>

Managing Releases

#install
helm install <release-name> <chart-name>/<local-chart-path>
#list installed release
helm list
#uninstall
helm uinstall <release-name>
#history
helm history <release-name>
#rollback
helm rollback <release-name> <revision> 

#See information of the release
helm get all/hooks/manifest/notes/values <release-name>
helm get manifest happy-panda

#Install dry run
helm install --dry-run --disable-openapi-validation <release-name> <chart-name>

Helm Built-in Objects

Objects are passed into a template from the template engine. The built-in values always begin with a capital letter. This is in keeping with Go's naming convention.

Release: This object describes the release itself. It has several objects inside of it:
    Release.Name
    Release.Namespace
    Release.IsUpgrade
    Release.IsInstall
    Release.Revision
    Release.Service

Values: Values passed into the template from the values.yaml file and from user-supplied files. By default, Values is empty.

Chart: The contents of the Chart.yaml file. Any data in Chart.yaml  will be accessible here.

Files:
    Files.Get is a function for getting a file by name (.Files.Get config.ini)
    Files.GetBytes is a function for getting the contents of a file as an array of bytes instead of as a string. This is useful for things like images.
    Files.Glob is a function that returns a list of files whose names match the given shell glob pattern.
    Files.Lines is a function that reads a file line-by-line. This is useful for iterating over each line in a file.
    Files.AsSecrets is a function that returns the file bodies as Base 64 encoded strings.
    Files.AsConfig is a function that returns file bodies as a YAML map.

Capabilities: This provides information about what capabilities the Kubernetes cluster supports.
    Capabilities.APIVersions is a set of versions.
    Capabilities.APIVersions.Has $version indicates whether a version (e.g., batch/v1) or resource (e.g., apps/v1/Deployment) is available on the cluster.
    Capabilities.KubeVersion and Capabilities.KubeVersion.Version is the Kubernetes version.
    Capabilities.KubeVersion.Major is the Kubernetes major version.
    Capabilities.KubeVersion.Minor is the Kubernetes minor version.
    Capabilities.HelmVersion is the object containing the Helm Version details, it is the same output of helm version
    Capabilities.HelmVersion.Version is the current Helm version in semver format.
    Capabilities.HelmVersion.GitCommit is the Helm git sha1.
    Capabilities.HelmVersion.GitTreeState is the state of the Helm git tree.
    Capabilities.HelmVersion.GoVersion is the version of the Go compiler used.

Template: Contains information about the current template that is being executed
    Template.Name: A namespaced file path to the current template (e.g. mychart/templates/mytemplate.yaml)
    Template.BasePath: The namespaced path to the templates directory of the current chart (e.g. mychart/templates).

Helm Lookup functions

template functions list: https://helm.sh/docs/chart_template_guide/function_list/

<function-name> arg1 arg2...
default "default value" .Values.<value>
lookup "apiVersion", "kind", "namespace", "name" -> resource or resource list
eg: lookup "v1" "Pod" "mynamespace" "mypod" => equivalent to: kubectl get pod mypod -n mynamespace

Operators Functions
eq, ne, lt, gt, and, or

Named Templates
{{- define "MY.NAME" }}
  # body of template here
{{- end }}

{{- template "MY.NAME" }}

{{- template "MY.NAME" . }} ##using the context

{{ include "MY.NAME" . | indent 4 }} ##include function can be used to pass values so, it is recommend to use include. Because template is an action, and not a function, there is no way to pass the output of a template call to other functions; the data is simply inserted inline.

Helm Passing the values

There are two ways to pass values one is using values.yml file and the other is –set flag. If both are used, --set values are merged into --values with higher precedence. Overrides specified with --set are persisted in a ConfigMap. Values that have been --set can be viewed for a given release with helm get values <release-name>. Values that have been --set can be cleared by running helm upgrade with --reset-values specified.

helm install -f values.yaml local-mysql bitnami/mysql -set db.auth.username="sth", db.auth.password="supersecret"