Helm
Introduction
Helm is a package manager for Kubernetes that simplifies the deployment and management of applications on a Kubernetes cluster.
It is organized as a collection of files inside of a directory. The directory name is the name of the chart (without versioning information). Thus, a chart describing WordPress would be stored in a
wordpress/
directory.
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
Chart
Introduction
A chart is a collection of files that describe a set of Kubernetes resources, such as deployments, services, config maps, and more. It provides a standardized and repeatable way to define, configure, and deploy complex applications on Kubernetes. So that, the resources can be deployed at once. It contains the following fields
apiVersion: The chart API version (required)
name: The name of the chart (required)
version: A SemVer 2 version (required)
kubeVersion: A SemVer range of compatible Kubernetes versions (optional)
description: A single-sentence description of this project (optional)
type: The type of the chart (optional)
keywords:
- A list of keywords about this project (optional)
home: The URL of this projects home page (optional)
sources:
- A list of URLs to source code for this project (optional)
dependencies: # A list of the chart requirements (optional)
- name: The name of the chart (nginx)
version: The version of the chart ("1.2.3")
repository: (optional) The repository URL ("https://example.com/charts") or alias ("@repo-name")
condition: (optional) A yaml path that resolves to a boolean, used for enabling/disabling charts (e.g. subchart1.enabled )
tags: # (optional)
- Tags can be used to group charts for enabling/disabling together
import-values: # (optional)
- ImportValues holds the mapping of source values to parent key to be imported. Each item can be a string or pair of child/parent sublist items.
alias: (optional) Alias to be used for the chart. Useful when you have to add the same chart multiple times
maintainers: # (optional)
- name: The maintainers name (required for each maintainer)
email: The maintainers email (optional for each maintainer)
url: A URL for the maintainer (optional for each maintainer)
icon: A URL to an SVG or PNG image to be used as an icon (optional).
appVersion: The version of the app that this contains (optional). Needn't be SemVer. Quotes recommended.
deprecated: Whether this chart is deprecated (optional, boolean)
annotations:
example: A list of annotations keyed by name (optional).
Repository & Dependencies
A Repository is the place where charts can be collected and shared. It's like Perl's CPAN archive or the Fedora Package Database, but for Kubernetes packages.
In Helm, one chart may depend on any number of other charts. These dependencies can be dynamically linked using the
dependencies
field inChart.yaml
or brought in to thecharts/
directory and managed manually.
dependencies:
- name: apache
version: 1.2.3
repository: https://example.com/charts
condition: apache.enabled,global.apache.enabled
tags:
- apache
- name: mysql
version: 3.2.1
repository: https://another.example.com/charts
- name: abc
alias: abc
repository: file://./abc
# specify correct version (find in file://./bot-builder-custom-helm-chart)
version: 1.0.0-a
After declaring the source of dependencies, it is needed to fetch the dependency charts
helm dependency update
When helm dependency update
retrieves charts, it will store them as chart archives in the charts/
directory. So the charts will be fetched in format of zip file
charts/
apache-1.2.3.tgz
mysql-3.2.1.tgz
Templates & Values
Introduction
Helm Chart templates are written in the Go template language
All template files are stored in a chart's
templates/
folder. When Helm renders the charts, it will pass every file in that directory through the template engine.Values (Variables) for the templates are supplied two ways:
Chart developers may supply a file called
values.yaml
inside of a chart. This file can contain default values.Chart users may supply a YAML file that contains values. This can be provided on the command line with
helm install
serviceAccount:
# Specifies whether a service account should be created
create: true
# Automatically mount a ServiceAccount's API credentials?
automount: true
# Annotations to add to the service account
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::855441561601:role/eks-role-bot-builder-custom-helm-chart
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: "bot-builder-custom-helm-chart"
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "bot-builder-custom-helm-chart.serviceAccountName" . }}
labels:
{{- include "bot-builder-custom-helm-chart.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
Override
Parent Values file can supply values to the chart as well as to any of its dependencies
E.g: Wordpress contains mysql chart and apache chart, the values can be declared in parent value file, it will override or supply the value to the child
The value must be started with child alias as a prefix
title: "My WordPress Site" # Sent to the WordPress template
mysql:
max_connections: 100 # Sent to MySQL
password: "secret"
apache:
port: 8080 # Passed to Apache
Values are namespaced, but namespaces are pruned. So for the WordPress chart, it can access the MySQL password field as
.Values.mysql.password
. But for the MySQL chart, the scope of the values has been reduced and the namespace prefix removed, so it will see the password field simply as.Values.password
.
Global
Helm supports special "global" value. example:
title: "My WordPress Site" # Sent to the WordPress template
global:
app: MyWordPress
mysql:
max_connections: 100 # Sent to MySQL
password: "secret"
apache:
port: 8080 # Passed to Apache
It will be regenerated the result like this
title: "My WordPress Site" # Sent to the WordPress template
global:
app: MyWordPress
mysql:
global:
app: MyWordPress
max_connections: 100 # Sent to MySQL
password: "secret"
apache:
global:
app: MyWordPress
port: 8080 # Passed to Apache
Pre-built Object
Release
: This object describes the release itself. It has several objects inside of it:Release.Name
: The release nameRelease.Namespace
: The namespace to be released into (if the manifest doesn’t override)Release.IsUpgrade
: This is set totrue
if the current operation is an upgrade or rollback.Release.IsInstall
: This is set totrue
if the current operation is an install.Release.Revision
: The revision number for this release. On install, this is 1, and it is incremented with each upgrade and rollback.Release.Service
: The service that is rendering the present template. On Helm, this is alwaysHelm
.
Values
: Values passed into the template from thevalues.yaml
file and from user-supplied files. By default,Values
is empty.Chart
: The contents of theChart.yaml
file. Any data inChart.yaml
will be accessible here. For example{{ .Chart.Name }}-{{ .Chart.Version }}
will print out themychart-0.1.0
.The available fields are listed in the Charts Guide
Files
: This provides access to all non-special files in a chart. While you cannot use it to access templates, you can use it to access other files in the chart. See the section Accessing Files for more.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.
Release
Introduction
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.
Command
Here are the commands of manage release based on the chart
# Init
helm create <name>
# List
helm list --namespace <namespace>
# Create helm release
helm install <release name> -f <directory of value file> <chart folder name> --namespace <namespace>
# Update
helm upgrade <release name> -f <directory of value file> <chart folder name> --namespace <namespace>
# Delete
helm uninstall <release name> --namespace <namespace>
Reference
Last updated
Was this helpful?