Helm 3 Quickstart Rules: - Resource Names should be unique to a release (limited to 63char) - For values use Initial lower case letters in order to distinguish local names from those built-in (GO). - For string values use quotes "" - Inverting the order is a common practice in templates (.val | quote) - prefix each defined template with the name of the chart - By convention, define functions should have a simple documentation block ({{/* ... */}}) describing what they do. - It is considered preferable to use include over template https://github.com/helm/charts
Files
/my-chart/ /my-chart/Chart.yaml /my-chart/values.yaml default values for a chart; overriden during helm install or helm upgrade /my-chart/charts/ description of a charts and subcharts; can access it from within a template /my-chart/templates/ helm evaluates charts here > processes through the template rendering engine > applies in K8s API
Files -> Templates
/my-chart/templates /my-chart/templates/NOTES.txt instructions shown on helm install /my-chart/templates/deployment.yaml /my-chart/templates/service.yaml /my-chart/templates/_helpers.tpl
Using Helm to create chart
helm create clientchart
Apply all templates/*
helm install ngclient ./clientchart helm install v1 ./clientchart helm install v2 ./clientchart helm install --debug --dry-run v3 ./clientchart helm get manifest ngclient helm uninstall ngclient helm install --dry-run --debug --set favoriteDrink=slurm good-puppy ./mychart helm get all ngclient
Variables
{{ .Release.Name }} **start at root "." namespace > "Release" namespace > "Name" namespace
Objects
.Release.Name .Release.Namespace .Release. IsUpgrade upgrade or rollback .Release. IsInstall .Release. Revision increments .Values passed from values.yaml .Chart any data from Chart.yaml {{ .Chart.Name }}-{{ .Chart.Version }} .Files other files .Files.Get config.ini .Files.GetBytes .Files.Lines iterate line by line .Files.AsSecrets files bodies as base64 .Files.AsConfig files bodies as YAML .Template.Name
Pipelines
Chaining together a series of template commands. upper | repeat 5 | default "tea" | quote drink: {{ .Values.favorite.drink | default (printf "%s-tea" (include "fullname" .)) }}
Functions
lookup look up resources in a running cluster
kubectl get pod mypod -n mynamespace lookup "v1" "Pod" "mynamespace" "mypod" kubectl get pods -n mynamespace lookup "v1" "Pod" "mynamespace" "" kubectl get pods --all-namespaces lookup "v1" "Pod" "" "" kubectl get namespace mynamespace lookup "v1" "Namespace" "" "mynamespace" kubectl get namespaces lookup "v1" "Namespace" "" ""
Flow Control (Actions)
{{ if PIPELINE }}
Do something
{{ else if OTHER PIPELINE }}
Do something else
{{ else }}
Default case
{{ end }}
Example: ENV: {{ quote .Values.environment }} drink: {{ quote .Values.favoriteDrink }} LOG: {{ .Values.log.level | upper | quote }} {{ if eq .Values.environment "staging" }}seed: true{{ end }}
Named Templates (partial or subtemplate)
define and template inside /templates/_helpers.tpl
Define
{{- define "ngclient.labels" }} labels: generator: helm date: {{ now | htmlDate }} {{- end }}
Use
{{- template "ngclient.labels" }}
Templates
------------------------ configmap ------------------------ apiVersion: v1 kind: ConfigMap metadata: name: {{ .Release.Name }}-configmap {{- template "ngclient.labels" . }} {{ include "ngclient.app" . | indent 4 }} data: env: {{ quote .Values.environment }} drink: {{ quote .Values.favoriteDrink }} {{- $relname := .Release.Name -}} {{- with .Values.log }} log: {{ .level | default "info" | quote }} logRelease: {{ $relname }} {{- end }} {{ if eq .Values.environment "staging" }}seed: true{{ end }} {{ include "ngclient.app" . | indent 2 }} ------------------------ configmap ------------------------
Created on 4/29/2020