Helm Deck
Helm Deck
Helm Deck
Mannambeth
Objectives
Packaging &
Range Chart Hooks Uploading
Signing
What is Helm?
Service
PVC
Secret
PV
Deployment
apiVersion: v1 apiVersion: v1 apiVersion: v1
kind: Secret kind: Service
metadata: kind: PersistentVolumeClaim
metadata:
name: wordpress-admin-password metadata:
name: wordpress
data: name: wp-pv-claim
labels:
key: CalksdlkeBGmxcv23kjsdlkjr== labels:
app: wordpress
app: wordpress
Service
spec:
spec:
ports:
>_ - port: 80
accessModes:
- ReadWriteOnce
selector: resources:
app: wordpress requests:
$ kubectl apply –f wp-secret.yaml tier: frontend
type: LoadBalancer PVC storage: 20Gi
Secret
>_
>_
apiVersion: apps/v1
kind: Deployment PV
$ kubectl apply –f wp-pvc.yaml
metadata: $ kubectl apply –f wp-svc.yaml
name: wordpress-mysql
apiVersion: v1
labels:
app: wordpress Deployment kind: PersistentVolume
>_
spec:
selector:
metadata:
name: pv0003
matchLabels: spec:
app: wordpress capacity:
$ kubectl apply –f wp-deploy.yaml storage: 20Gi
tier: mysql
strategy: volumeMode: Filesystem
type: Recreate accessModes:
template: - ReadWriteOnce
metadata:
labels:
app: wordpress >_
tier: mysql
spec:
containers: $ kubectl apply –f wp-pv.yaml
- image: mysql:5.6
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
apiVersion: v1
app: wordpress
kind: Secret
spec:
metadata:
accessModes:
name: wordpress-admin-password
- ReadWriteOnce
data:
resources:
key: CalksdlkeBGmxcv23kjsdlkjr==
apiVersion: v1
requests:
kind: Service
storage: 20Gi
metadata:
Service name: wordpress
apiVersion: v1
labels:
kind: PersistentVolume
app: wordpress
metadata:
spec:
name: pv0003
ports:
spec:
PVC - port: 80
capacity:
selector:
storage: 20Gi
app: wordpress
Secret volumeMode: Filesystem
tier: frontend
accessModes:
type: LoadBalancer
- ReadWriteOnce
apiVersion: apps/v1
PV
kind: Deployment
metadata:
name: wordpress-mysql
labels:
Deployment
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
Service
PVC
Secret
PV
Deployment
INSTALL
>_
$ helm install wordpress values.yaml
Service
Deployment
Install & Configuration
Installing Helm
>_
$ sudo snap install helm --classic
kubectl
https://helm.sh/docs/intro/install/
Labs
helm cli
helm cli
Helm 2 Helm 3
Tiller
3-Way Strategic Merge Patch
Helm 2
wordpress wordpress
Revision: 1
wordpress
$ helm install wordpress $ kubectl set image wordpress \ $ helm rollback wordpress
wordpress:5.8-apache
3 Live State
Helm Components
Helm Components
Revision: 1 Revision: 1
Revision: 2 Revision: 2
Revision: 3 Revision: 3
Release Release
Chart
helm cli
Helm Charts
hello-world
Helm Charts
wordpress
Helm Releases
>_
# helm install [release-name][chart-name]
Revision: 3 Revision: 3
# helm install bitnami/wordpress
Revision: 2 Revision: 2
Release Release
my-site my-SECOND-site
Helm Repositories
ArtifactHub.io
TrueCharts Bitnami
Helm Repositories
Helm Repositories
Helm Charts
Helm Charts
Template
apiVersion: v2
appVersion: 5.8.1
version: 12.1.27
name: wordpress
description: Web publishing platform for building blogs and websites.
type: application
dependencies:
- condition: mariadb.enabled
name: mariadb
repository: https://charts.bitnami.com/bitnami
version: 9.x.x
<code hidden>
keywords:
- application
- blog
- wordpress
maintainers:
- email: containers@bitnami.com
name: Bitnami
home: https://github.com/bitnami/charts/tree/master/bitnami/wordpress
icon: https://bitnami.com/assets/stacks/wordpress/img/wordpress-stack-220x234.png
hello-world-chart
>_
$ helm --help
The Kubernetes package manager
Usage:
helm [command]
Available Commands:
completion generate autocompletion scripts for the specified shell
create create a new chart with the given name
dependency manage a chart's dependencies
env helm client environment information
get download extended information of a named release
help Help about any command
history fetch release history
Helm CLI
>_
$ helm repo --help
This command consists of multiple subcommands to interact with chart repositories.
Usage:
helm repo [command]
Available Commands:
add add a chart repository
index generate an index file given a directory containing packaged charts
list list chart repositories
remove remove one or more chart repositories
update update information of available charts locally from chart repositories
Usage:
helm repo update [flags]
Aliases:
update, up
Wordpress
Wordpress
>_
$ helm search wordpress
Search provides the ability to search for Helm charts in the various places
they can be stored including the Artifact Hub and repositories you have added.
Use search subcommands to search different locations for charts.
Usage:
helm search [command]
Available Commands:
hub search for charts in the Artifact Hub or your own hub instance
repo search repositories for a keyword in charts
>_
$ helm repo add bitnami https://charts.bitnami.com/bitnami
NAME: my-release
LAST DEPLOYED: Wed Nov 10 18:03:50 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: wordpress
CHART VERSION: 12.1.27
APP VERSION: 5.8.1
Your WordPress site can be accessed through the following DNS name
from within your cluster:
>_
$ helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-release default 1 2021-11-10 18:03:50.414174217 +0000 UTC deployed wordpress-12.1.27 5.8.1
>_
$ helm repo
This command consists of multiple subcommands to interact with chart repositories.
Usage:
helm repo [command]
Available Commands:
add add a chart repository
index generate an index file given a directory containing packaged charts
list list chart repositories
remove remove one or more chart repositories
update update information of available charts locally from chart repositories
>_
image: values.yaml
$ helm install --set wordpressBlogName="Helm Tutorials" my-release bitnami/wordpress registry: docker.io
repository: bitnami/wordpress
tag: 5.8.2-debian-10-r0
--set wordpressEmail="john@example.com"
## @param wordpressUsername WordPress username
##
wordpressUsername: user
## @param wordpressPassword WordPress user
password
## Defaults to a random 10-character alphanumeric
string if not set
##
wordpressPassword: ""
## @param existingSecret
##
existingSecret: ""
## @param wordpressEmail WordPress user email
##
wordpressEmail: user@example.com
## @param wordpressFirstName WordPress user first
name
##
## @param wordpressBlogName Blog name
##
wordpressBlogName: User's Blog!
Custom Parameters from a YAML file
--values
>_
custom-values.yaml
$ helm install --values custom-values.yaml my-release bitnami/wordpress
wordpressBlogName: Helm Tutorials
wordpressEmail: john@example.com
Helm Pull
>_
image: values.yaml
$ helm pull bitnami/wordpress registry: docker.io
repository: bitnami/wordpress
tag: 5.8.2-debian-10-r0
$ helm pull --untar bitnami/wordpress ## @param wordpressUsername WordPress username
##
wordpressUsername: user
$ ls ## @param wordpressPassword WordPress user
password
## Defaults to a random 10-character alphanumeric
wordpress string if not set
##
wordpressPassword: ""
$ ls wordpress ## @param existingSecret
##
Mode LastWriteTime Length Name existingSecret: ""
---- ------------- ------ ---- ## @param wordpressEmail WordPress user email
##
d----- 13-Nov-21 10:36 PM ci wordpressEmail: user@example.com
d----- 13-Nov-21 10:36 PM templates ## @param wordpressFirstName WordPress user first
-a---- 13-Nov-21 10:36 PM 354 .helmignore name
##
-a---- 13-Nov-21 10:36 PM 399 Chart.lock ## @param wordpressBlogName Blog name
-a---- 13-Nov-21 10:36 PM 984 Chart.yaml ##
-a---- 13-Nov-21 10:36 PM 51019 README.md wordpressBlogName: User's Blog!
>_
Revision: 2 Revision: 2
Revision: 1 Revision: 1
Release Release
my-site my-SECOND-site
Helm Upgrade
>_
Containers:
nginx: nginx-release
Container ID: docker://81bb5ad6b5..
Image: docker.io/bitnami/nginx:1.19.2-debian-10-r28
Image ID: docker-pullable://bitnami/nginx@sha256:2fcaf026b8acb7a..
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Helm Upgrade
>_
>_
$ helm list
NAME NAMESPACE REVISION STATUS CHART APP VERSION
nginx-release default 2 deployed nginx-9.5.13 1.21.4
nginx-release
Helm Rollback
>_
$ helm list
NAME NAMESPACE REVISION STATUS CHART APP VERSION
nginx-release default 2 deployed nginx-9.5.13 1.21.4
Revision: 3
$ helm history nginx-release
Revision: 2
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Mon Nov 15 19:20:51 2021 superseded nginx-7.1.0 1.19.2 Install complete
2 Mon Nov 15 19:25:55 2021 deployed nginx-9.5.13 1.21.4 Upgrade complete Revision: 1
nginx-release
$ helm rollback nginx-release 1
Rollback was a success! Happy Helming!
>_
wordpress-release
Understanding
Helm Charts
Writing
Templating Functions
Charts
Revision: 2
Revision: 1
Initiate Backup
(Hook)
wordpress-release
Writing Our First Helm Chart
hello-world-chart
apiVersion: v1 service.yaml apiVersion: apps/v1 deployment.yaml
templates kind: Service kind: Deployment
metadata: metadata:
values.yaml name: hello-world
spec:
name: hello-world
spec:
type: NodePort replicas: 2
Chart.yaml ports: selector:
- port: 80 matchLabels:
targetPort: http app: hello-world
LICENSE protocol: TCP template:
name: http metadata:
selector: labels:
README.md app: hello-world app: hello-world
spec:
containers:
- name: hello-world
image: nginx
$ helm create nginx-chart ports:
- name: http
containerPort: 80
$ ls nginx-chart protocol: TCP
charts Chart.yaml templates values.yaml
>_
$ cd nginx-chart
apiVersion: v2 Chart.yaml
$ vi Chart.yaml name: nginx-chart
description: ABasic
Helm nginx
chart website
for Kubernetes
$ ls templates #...
type: application
deployment.yaml _helpers.tpl hpa.yaml ingress.yaml
NOTES.txt serviceaccount.yaml service.yaml tests #...
version: 0.1.0
#...
$ rm -r templates/* appVersion: "1.16.0"
maintainers:
- email: john@example.com
name: john smith
>_
hello-world
hello-world-1 hello-world-2
Templatize
>_
hello-world-1-nginx
hello-world-1
Templatize
Template Directive
Go Template Language
Templatize
hello-world-1-nginx
Objects
>_
hello-world-1-nginx hello-world-2-nginx
hello-world-1 hello-world-2
Templatize
>_
$ helm install hello-world-1 ./nginx-chart apiVersion: v1 service.yaml apiVersion: apps/v1 deployment.yaml
--set replicaCount=2 kind: Service kind: Deployment
metadata: metadata:
--set image=nginx name: hello-world
{{ .Release.Name }}-svc name: hello-world
{{ .Release.Name }}-nginx
spec: spec:
type: NodePort replicas: 2{{ .Values.replicaCount }}
ports: selector:
- port: 80 matchLabels:
targetPort: http app: hello-world
protocol: TCP template:
name: http metadata:
selector: labels:
app: hello-world app: hello-world
spec:
containers:
- name: hello-world
image: {{
nginx
.Values.image }}
ports:
- name: http
containerPort: 80
protocol: TCP
replicaCount: 2
image: nginx
Templatize
image:
repository: nginx
pullPolicy: IfNotPresent
{{ .Values.image.repository
nginx }}:{{ .Values.image.tag
1.16.0 }}
tag: "1.16.0"
Templatize
image:
repository: nginx
pullPolicy: IfNotPresent
{{ .Values.image.repository
nginx
}}:{{
1.16.0
.Values.image.tag }}
tag: "1.16.0"
Templatize
Lint
Template
Dry Run
Lint
>_
$ helm lint ./nginx-chart service.yaml
apiVersion: v1 apiVersion: apps/v1 deployment.yaml
kind: Service kind: Deployment
==> Linting ./nginx-chart/
metadata: metadata:
[INFO] Chart.yaml: icon is recommended name: hello-world
{{ .Release.Name }}-svc name: hello-world
{{ .Releese.Name
.Release.Name }}-nginx
[ERROR] templates/: template: nginx- spec: spec:
chart/templates/deployment.yaml:4:19: executing "nginx- type: NodePort replicas: 2{{ .Values.replicaCount }}
chart/templates/deployment.yaml" at <.Releese.Name>: nil ports: selector:
pointer evaluating interface {}.Name - port: 80 matchLabels:
targetPort: http app: hello-world
[ERROR] templates/deployment.yaml: unable to parse YAML: protocol: TCP template:
error converting YAML to JSON: yaml: line 20: did not name: http metadata:
find expected '-' indicator selector: labels:
app: hello-world app: hello-world
spec:
Error: 1 chart(s) linted, 1 chart(s) failed
containers:
- name: hello-world
image: {{
nginx
.Values.image }}
$ helm lint ./nginx-chart ports:
- name: http
==> Linting ./nginx-chart/ containerPort: 80
[INFO] Chart.yaml: icon is recommended protocol: TCP
replicaCount: 2
image: nginx
Validating Template
>_
$$ helm
helm template
template ./nginx-chart
hello-world-1 ./nginx-chart service.yaml
apiVersion: v1 apiVersion: apps/v1 deployment.yaml
--- kind: Service kind: Deployment
# ---
Source: nginx-chart/templates/deployment.yaml metadata: metadata:
# Source: nginx-chart/templates/deployment.yaml
apiVersion: apps/v1
apiVersion: apps/v1 name: hello-world
{{ .Release.Name }}-svc name: hello-world
{{ .Release.Name }}-nginx
kind: Deployment
kind: Deployment
metadata:
spec: spec:
metadata:
name: RELEASE-NAME-nginx type: NodePort replicas: 2{{ .Values.replicaCount }}
name: hello-world-1-nginx
spec: ports: selector:
spec:
replicas: 2 - port: 80 matchLabels:
replicas: 2
selector: targetPort: http app: hello-world
selector:
matchLabels: protocol: TCP template:
matchLabels:
app: hello-world name: http metadata:
app: hello-world
template:
template:
selector: labels:
metadata:
metadata: app: hello-world app: hello-world
labels:
labels:
app: hello-world spec:
spec: app: hello-world containers:
spec:
containers: - name: hello-world
containers:
- name: hello-world image: {{
nginx
.Values.image }}
-image:
name: nginx
hello-world ports:
image: nginx
ports: - name: http
ports:
- name: http containerPort: 80
-containerPort:
name: http 8
containerPort: 8 protocol: TCP
---
# ---
Source: nginx-chart/templates/service.yaml
# Source: nginx-chart/templates/service.yaml
apiVersion: v1
apiVersion:
kind: Service v1
kind: Service
# Default values for nginx-chart. values.yaml
metadata: # This is a YAML-formatted file.
metadata:
name: RELEASE-NAME-nginx # Declare variables to be passed into your templates.
name: hello-world-1-nginx
spec:
spec:
type: NodePort replicaCount: 2
type: NodePort
ports: image: nginx
ports:
- port: 80
-targetPort:
port: 80 http
targetPort:
protocol: TCP http
protocol:
name: http TCP
name: http
selector:
Validating Template
>_
$ helm template ./nginx-chart service.yaml
apiVersion: v1 apiVersion: apps/v1 deployment.yaml
Error: YAML parse error on nginx-chart/templates/deployment.yaml: kind: Service kind: Deployment
error converting YAML to JSON: yaml: line 5: mapping values are not metadata: metadata:
allowed in this context name: hello-world
{{ .Release.Name }}-svc name: hello-world
{{ .Release.Name }}-nginx
spec: spec:
type: NodePort replicas: 2{{ .Values.replicaCount }}
ports: selector:
$ helm template ./nginx-chart --debug - port: 80 matchLabels:
targetPort: http app: hello-world
apiVersion: apps/v1 protocol: TCP template:
kind: Deployment name: http metadata:
metadata: selector: labels:
name: hello-world app: hello-world app: hello-world
spec: spec:
replicas: 2
containers:
selector:
matchLabels:
- name: hello-world
app: hello-world image: {{
nginx
.Values.image }}
template: ports:
- name: http
Error: YAML parse error on nginx-chart/templates/deployment.yaml: containerPort: 80
error converting YAML to JSON: yaml: line 5: mapping values are not protocol: TCP
allowed in this context
replicaCount: 2
image: nginx
Dry Run
>_
$ helm install hello-world-1 ./nginx-chart --dry-run apiVersion: v1 service.yaml apiVersion: apps/v1 deployment.yaml
kind: Service kind: Deployment
Error: unable to build kubernetes objects from release
metadata: metadata:
manifest: error validating "": error validating data: name: hello-world
{{ .Release.Name }}-svc name: hello-world
{{ .Release.Name }}-nginx
[ValidationError(Deployment.spec.template.spec): unknown spec: spec:
field "container" in io.k8s.api.core.v1.PodSpec, type: NodePort replicas: 2{{ .Values.replicaCount }}
ValidationError(Deployment.spec.template.spec): missing ports: selector:
required field "containers" in - port: 80 matchLabels:
io.k8s.api.core.v1.PodSpec] targetPort: http app: hello-world
protocol: TCP template:
name: http metadata:
selector: labels:
$ helm install hello-world-1 ./nginx-chart --dry-run app: hello-world app: hello-world
spec:
NAME: hello-world-1 containers:
container:
LAST DEPLOYED: Fri Nov 19 18:34:51 2021 - name: hello-world
NAMESPACE: default image: {{
nginx
.Values.image }}
STATUS: pending-install ports:
REVISION: 1 - name: http
TEST SUITE: None containerPort: 80
HOOKS: protocol: TCP
MANIFEST:
---
# Source: nginx-chart/templates/service.yaml # Default values for nginx-chart. values.yaml
apiVersion: v1 # This is a YAML-formatted file.
# Declare variables to be passed into your templates.
kind: Service
metadata: replicaCount: 2
name: hello-world-1-nginx image: nginx
spec:
type: NodePort
ports:
- port: 80
Functions
apiVersion: apps/v1 templates/deployment.yaml apiVersion: apps/v1 deployment.yaml
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ .Release.Name }}-nginx
hello-world name: hello-world
spec: spec:
replicas: {{
2 .Values.replicaCount }} replicas: 2
selector: selector:
matchLabels: matchLabels:
values.yaml
app: hello-world app: hello-world
template: replicaCount: 2 template:
metadata: metadata:
labels: image: labels:
app: hello-world repository: nginx app: hello-world
spec: pullPolicy: IfNotPresent spec:
containers: tag: "1.16.0" containers:
- name: hello-world - name: hello-world
image: {{
nginx
.Values.image.repository }} image: nginx
ports: ports:
- name: http - name: http
containerPort: 80 containerPort: 80
protocol: TCP protocol: TCP
upper("helm")
"helm" "HELM"
trim(" ")
" helm " "helm"
Templatize
Chart Details
{{ .Values.image.repository }} image: nginx
String Functions
Cryptographic
Date Dictionaries Encoding
and Security
Type
Regex String URL
Conversion
https://helm.sh/docs/chart_template_guide/function_list/
apiVersion: apps/v1 templates/deployment.yaml apiVersion: apps/v1 deployment.yaml
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ .Release.Name }}-nginx
hello-world name: hello-world
spec: spec:
replicas: {{
2 .Values.replicaCount }} replicas: 2
selector: selector:
matchLabels: matchLabels:
values.yaml
app: hello-world app: hello-world
template: replicaCount: 2 template:
metadata: metadata:
labels: image: labels:
app: hello-world repository: nginx app: hello-world
spec: pullPolicy: IfNotPresent spec:
containers: tag: "1.16.0" containers:
- name: hello-world - name: hello-world
image: {{
nginx
.Values.image.repository }} image: nginx
ports: ports:
- name: http - name: http
containerPort: 80 containerPort: 80
protocol: TCP protocol: TCP
apiVersion: apps/v1 templates/deployment.yaml apiVersion: apps/v1 deployment.yaml
kind: Deployment kind: Deployment
metadata: metadata:
name: {{ .Release.Name }}-nginx
hello-world name: hello-world
spec: spec:
replicas: {{
2 .Values.replicaCount }} replicas: 2
selector: selector:
matchLabels: matchLabels:
values.yaml
app: hello-world app: hello-world
template: replicaCount: 2 template:
metadata: metadata:
labels: image: labels:
app: hello-world repository: nginx app: hello-world
spec: pullPolicy: IfNotPresent spec:
containers: tag: "1.16.0" containers:
- name: hello-world - name: hello-world
image: {{
nginx
default "nginx" .Values.image.repository }} image: nginx
ports: ports:
- name: http - name: http
containerPort: 80 containerPort: 80
protocol: TCP protocol: TCP
Pipelines
Pipelines
>_
$ echo "abcd"
abcd
kind: Service
replicaCount: 2 metadata:
image: nginx name: {{ .Release.Name }}-nginx
labels:
orgLabel: payroll
org: {{ .Values.orgLabel }}
payroll
spec:
ports:
- port: 80
name: http
selector:
app: hello-world
Conditionals
orgLabel = "payroll"
print(orgLabel)
Conditionals
orgLabel = "payroll"
if orgLabel:
print(orgLabel)
end
Conditionals
kind: Service
replicaCount: 2 metadata:
image: nginx name: {{ .Release.Name }}-nginx
labels:
orgLabel: payroll
org: {{ .Values.orgLabel }}
payroll
spec:
ports:
- port: 80
name: http
selector:
app: hello-world
Conditionals
kind: Service
replicaCount: 2 metadata:
image: nginx name: {{ .Release.Name }}-nginx
orgLabel: payroll {{ if .Values.orgLabel }}
labels:
org: {{ .Values.orgLabel }}
payroll
{{ end }}
spec:
ports:
- port: 80
name: http
selector:
app: hello-world
Conditionals
orgLabel = "payroll"
if orgLabel:
print(orgLabel)
end
Conditionals
orgLabel = "payroll"
if orgLabel:
print(orgLabel)
else:
print("nothing")
end
Conditionals
orgLabel = "payroll"
if orgLabel:
print(orgLabel)
else if orgLabel=="hr":
print("human resources")
else:
print("nothing")
end
Conditionals
apiVersion: v1 service.yaml
kind: Service
metadata:
name: {{ .Release.Name }}-nginx
{{- if .Values.orgLabel }}
labels:
org: {{ .Values.orgLabel }}
payroll
{{- end }}
spec:
ports:
- port: 80
name: http
selector:
app: hello-world
Conditionals
apiVersion: v1 configmap.yaml
kind: ConfigMap
Release Values metadata:
name: {{ .Release.Name }}-appinfo
data:
background: {{ .Values.app.ui.bg }}
Name app foreground: {{ .Values.app.ui.fg }}
database: {{ .Values.app.db.name }}
connection: {{ .Values.app.db.conn }}
ui db
bg fg name conn
With
Root
apiVersion: v1 configmap.yaml
kind: ConfigMap
Release Values metadata:
name: {{ .Release.Name }}-appinfo
data:
{{- with .Values.app }}
Name app
background: {{ .Values.app.ui.bg }}
foreground: {{ .Values.app.ui.fg }}
database: {{ .Values.app.db.name }}
connection: {{ .Values.app.db.conn }}
ui db {{- end }}
bg fg name conn
With
Root
apiVersion: v1 configmap.yaml
kind: ConfigMap
Release Values metadata:
name: {{ .Release.Name }}-appinfo
data:
{{- with .Values.app }}
Name app
background: {{ .Values.app.ui.bg }}
foreground: {{ .Values.app.ui.fg }}
database: {{ .Values.app.db.name }}
connection: {{ .Values.app.db.conn }}
ui db {{- end }}
bg fg name conn
With
Root
apiVersion: v1 configmap.yaml
kind: ConfigMap
Release Values metadata:
name: {{ .Release.Name }}-appinfo
data:
{{- with .Values.app }}
Name app
{{- with .ui }}
background: {{ .Values.app.ui.bg }}
foreground: {{ .Values.app.ui.fg }}
{{- end }}
ui db database: {{ .Values.app.db.name }}
connection: {{ .Values.app.db.conn }}
{{- end }}
bg fg name conn
With
Root
apiVersion: v1 configmap.yaml
kind: ConfigMap
Release Values metadata:
name: {{ .Release.Name }}-appinfo
data:
{{- with .Values.app }}
Name app
{{- with .ui }}
background: {{ .Values.app.ui.bg }}
foreground: {{ .Values.app.ui.fg }}
{{- end }}
ui db database: {{ .Values.app.db.name }}
connection: {{ .Values.app.db.conn }}
{{- end }}
bg fg name conn
With
Root
apiVersion: v1 configmap.yaml
kind: ConfigMap
Release Values metadata:
name: {{ .Release.Name }}-appinfo
data:
{{- with .Values.app }}
Name app
{{- with .ui }}
background: {{ .Values.app.ui.bg }}
foreground: {{ .Values.app.ui.fg }}
{{- end }}
ui db {{- with .db }}
database: {{ .Values.app.db.name }}
connection: {{ .Values.app.db.conn }}
{{- end }}
{{- end }}
bg fg name conn
With
apiVersion: v1 configmap.yaml
kind: ConfigMap
Release Values metadata:
name: {{ .Release.Name }}-appinfo
data:
{{- with .Values.app }}
Name app
{{- with .ui }}
background: {{ .Values.app.ui.bg }}
foreground: {{ .Values.app.ui.fg }}
{{- end }}
ui db {{- with .db }}
database: {{ .Values.app.db.name }}
connection: {{ .Values.app.db.conn }}
{{- end }}
release: {{ $.Release.Name }}
bg fg name conn {{- end }}
Range
Loops
1 i
2 i
3 i
for i in 1 to 10: 1
4 i print i 2
end 3
5 i
4
6 i 5
6
7 i
7
8 i 8
9 i 9
10
10 i
regions: values.yaml apiVersion: v1 configmap.yaml
Values
apiVersion: v1 configmap.yaml
regions kind: ConfigMap
metadata:
name: RELEASE-NAME-regioninfo
ohio .
data:
newyork . regions:
- "ohio"
ontario . - "newyork"
- "ontario"
london . - "london"
- "singapore"
singapore . - "mumbai"
mumbai .
Named Templates
apiVersion: v1 service.yaml apiVersion: apps/v1 deployment.yaml
kind: Service kind: Deployment
metadata: metadata:
name: {{ .Release.Name }}-nginx name: {{ .Release.Name }}-nginx
labels: labels:
app.kubernetes.io/name: nginx app.kubernetes.io/name: nginx
app.kubernetes.io/instance: nginx app.kubernetes.io/instance: nginx
spec: spec:
ports: selector:
- port: 80 matchLabels:
targetPort: http app.kubernetes.io/name: nginx
protocol: TCP app.kubernetes.io/instance: nginx
name: http template:
selector: metadata:
app: hello-world labels:
app.kubernetes.io/name: nginx
app.kubernetes.io/instance: nginx
spec:
containers:
- name: nginx
image: "nginx:1.16.0"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
protocol: TCP
Template
https://stackoverflow.com/questions/71086697/how-does-template-and-include-differ-in-helm
Chart Hooks
$ helm upgrade wordpress-release bitnami/wordpress
Revision: 2
Revision: 1
Initiate Backup
(Hook)
wordpress-release
upgrade
$ helm upgrade verify render upgrade
pre-upgrade hook
pre-
upgrade
$ helm upgrade verify render upgrade
upgrade
Backup database
post-upgrade hook
pre- post-
upgrade
$ helm upgrade verify render upgrade
upgrade upgrade
Email Status
hooks
pre- post-
install
$ helm install verify render install
install install
pre- post-
install
$ helm delete verify render delete
delete delete
pre- post-
upgrade
$ helm upgrade verify render upgrade
upgrade upgrade
pre- post-
install
$ helm rollback verify render rollback
rollback rollback
Creating Hooks
pre-
template:
metadata:
service.yaml upgrade name: {{ .Release.Name }}-nginx
spec:
restartPolicy: Never
deployment.yaml containers:
- name: pre-upgrade-backup-job
image: "alpine"
secret.yaml command: ["/bin/backup.sh"]
Pod
Job
backup-job.yaml
backup.sh
Creating Hooks
backup.sh
pre-upgrade hook
annotations:
"helm.sh/hook": pre-upgrade
spec:
template:
metadata:
pre- name: {{ .Release.Name }}-nginx
upgrade
$ helm upgrade verify render upgrade spec:
upgrade restartPolicy: Never
containers:
- name: pre-upgrade-backup-job
image: "alpine"
command: ["/bin/backup.sh"]
3 Setup Banner
5 Backup database
-4 Email Announcement
pre-upgrade hook
annotations:
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "5"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
pre- name: {{ .Release.Name }}-nginx
upgrade
$ helm upgrade verify render upgrade spec:
upgrade restartPolicy: Never
containers:
- name: pre-upgrade-backup-job
image: "alpine"
command: ["/bin/backup.sh"]
-4 Email Announcement
3 Setup Banner
5 Backup database
hook-succeeded
hook-failed
before-hook-creation
Packaging and Signing Charts
Packaging & Uploading
>_
$ ls nginx-chart
charts Chart.yaml templates values.yaml README.md
LICENSE
public Key
nginx-chart-0.1.0.tgz
Private Key
Packaging
>_
$ gpg --quick-generate-key "John Smith"
gpg: keybox '/home/vagrant/.gnupg/pubring.kbx' created
About to create a key for:
"John Smith"
public Key
Continue? (Y/n) Y
gpg: /home/vagrant/.gnupg/trustdb.gpg: trustdb created
gpg: key 70D5188339885A0B marked as ultimately trusted Online Chart Repository
gpg: directory '/home/vagrant/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as
'/home/vagrant/.gnupg/openpgp-
revocs.d/20F2395A3176A22DD33DA45470D5188339885A0B.rev'
public and secret key created and signed.
>_
$ gpg --list-keys
>_
$ ls
$ ls
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
apiVersion: v2
appVersion: 1.16.0
description: A Helm chart for Kubernetes
maintainers:
- - email: john@example.com
name: john smith
name: nginx-chart
type: application
version: 0.1.0
...
files:
nginx-chart-0.1.0.tgz: sha256:b7d05022a9617ab953a3246bc7ba6a9de9d4286b2e78e3ea7975cc54698c4274
-----BEGIN PGP SIGNATURE-----
...
=kser
-----END PGP SIGNATURE-----
$ sha256sum nginx-chart-0.1.0.tgz
b7d05022a9617ab953a3246bc7ba6a9de9d4286b2e78e3ea7975cc54698c4274 nginx-chart-0.1.0.tgz
Verify Signature
>_
>_
$ ls
nginx-chart nginx-chart-0.1.0.tgz nginx-chart-0.1.0.tgz.prov
$ mkdir nginx-chart-files
$ ls nginx-chart-files
index.yaml nginx-chart-0.1.0.tgz nginx-chart-0.1.0.tgz.prov
apiVersion: v1 index.yaml
entries:
nginx-chart:
- apiVersion: v2
appVersion: 1.16.0
created: "2021-12-01T15:29:35.073405539Z"
description: A Helm chart for Kubernetes
digest: 2c83c29dc4c56d20c45c3de8eff521fbfb6ef6c0b66854a6f4b5539bebcff879
maintainers:
- email: john@example.com
name: john smith
name: nginx-chart
type: application
urls:
- https://charts.bitnami.com/bitnami/nginx-chart-0.1.0.tgz
version: 0.1.0
generated: "2021-12-01T15:29:35.047718855Z"
https://example-charts.storage.googleapis.com
>_
$ helm repo add our-cool-charts https://example-charts.storage.googleapis.com
Packaging &
Range Chart Hooks Uploading
Signing