Helm usage
Setup example project
helm create mychart
rm -rf mychart/templates/*
configmap.yaml
helm install full-coral .
helm get manifest full-coral
helm uninstall full-coral
# test template rendering
helm install --debug --dry-run goodly-guppy .
Built-in objects
https://helm.sh/docs/chart_template_guide/builtin_objects/
Release
:Release.Name
Release.Namespace
: The namespace to be released into (if the manifest doesn’t override)Release.IsUpgrade
: This is set to true if the current operation is an upgrade or rollback.Release.IsInstall
: This is set to true 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 always Helm.
values
values.yaml
에 넣은 내용을{{ .Values. }}
템플릿 문법으로 사용 가능helm install --set myvalue=value
로 override 가능--set myvalue=null
로 제거 가능
Template functions and pipeline
- Template function: 대부분 Go template 함수에서 가져옴. https://godoc.org/text/template
Pipelines
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
drink: {{ quote .Values.favorite.drink }} # use template
food: {{ .Values.favorite.food | upper | quote }} # use pipelines
Using default
function
- 가장 많이 쓰이는 함수 중 하나. 값이 없으면 default value 사용
- 실제로는 잘 안쓰이고 모든 값이
values.yaml
에 있어야됨. 아래에 나오는if
등과 같이 사용
drink: {{ .Values.favorite.drink | default "tea" | quote }}
Flowcontrol
if
/else
with
range
define
template
: imports a named templateblock
{{ if PIPELINE }}
# Do something
{{ else if OTHER PIPELINE }}
# Do something else
{{ else }}
# Default case
{{ end }}
예시
apiVersion: v1
kind: ConfigMap
metadata:
name: mychart-configmap
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
drink: {{ .Values.favorite.drink | default "tea" | quote }}
food: {{ .Values.favorite.food | upper | quote }}
{{ if eq .Values.favorite.drink "coffee"}}mug: true{{end}}
아래와 같이 whitespace 맞춰줄 수 있음 ({{- ... -}}
)
...
food: {{ .Values.favorite.food | upper | quote }}
{{- if eq .Values.favorite.drink "coffee" }}
mug: true
{{- end }}
Variables
$name
, :-
를 사용하여 variable 사용 가능
apiVersion: v1
kind: ConfigMap
metadata:
name: mychart-configmap
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- $relname := .Release.Name -}}
{{- with .Values.favorite }}
drink: {{ .drink | default "tea" | quote }}
food: {{ .food | upper | quote }}
release: {{ $relname }}
{{- end }}
toppings: |-
{{- range $index, $topping := .Values.pizzaToppings }}
{{ $index }}: {{ $topping }}
{{- end }}
이런식으로 key, value로 지정하게 쓰임
...
{{- range $key, $val := .Values.favorite }}
{{ $key }}: {{ $val | quote }}
{{- end }}