Day 10: Helm – Your Own Chart
Goal: notes becomes a Helm chart with a hook Job, a test and a schema; the release takes over the running database including its data. · Duration: approx. 120 min · Prerequisite: Day 9
Briefing
- A chart is a folder:
Chart.yaml(name, versions),values.yaml(default values),templates/(manifests with Go templates), optionallyvalues.schema.json(validation of the values). - Hooks are objects with an annotation that Helm creates at specific
points in time – here migrate after
installand before everyupgrade. - The chart creates the same objects as the manifests from Day 8, with
the same names. That is why the new StatefulSet finds the old PVC
data-db-0. - Namespace, PSA labels, quota, ServiceAccount and Secrets stay with
kubectl.
k8s/namespace.yaml, k8s/secrets.sh (platform, kubectl)
chart/notes/ (application, helm)
Chart.yaml values.yaml values.schema.json .helmignore
templates/ _helpers.tpl api web worker db configmap migrate-job NOTES.txt
tests/test-api.yaml
Drill 1: helm create – Look and Throw
Away
source ~/k8s-lab/setup/env.sh
mkdir -p ~/k8s-lab/tag10 && cd ~/k8s-lab/tag10
cp -R "$LAB/code/notes/." . && cp -R "$LAB/code/tag09/notes/." .
helm create demo
find demo -type f | sort
wc -l demo/values.yaml demo/templates/deployment.yaml
helm template demo ./demo | grep -E '^kind:' | sort | uniq -c
rm -rf demoExpected (abridged):
Creating demo
demo/.helmignore
demo/Chart.yaml
demo/templates/NOTES.txt
demo/templates/_helpers.tpl
demo/templates/deployment.yaml
demo/templates/hpa.yaml
demo/templates/httproute.yaml
demo/templates/ingress.yaml
demo/templates/service.yaml
demo/templates/serviceaccount.yaml
demo/templates/tests/test-connection.yaml
demo/values.yaml
161 demo/values.yaml
78 demo/templates/deployment.yaml
239 total
1 kind: Deployment
1 kind: Pod
1 kind: Service
1 kind: ServiceAccount
The scaffold is a chart for any application: Ingress, HTTPRoute, autoscaler, everything can be switched off, 161 lines of values. For notes, most of it would be dead weight. You only take the idea – structure, helpers, labels – and build the chart from your manifests.
Save your progress? Sign up for free
Drill 2: Chart.yaml and
values.yaml
mkdir -p chart/notes/templates/tests
cat > chart/notes/Chart.yaml <<'EOF'
# chart/notes/Chart.yaml – state at end of Day 10
apiVersion: v2
name: notes
description: Die notes-Anwendung aus dem Trainingslager (api, web, worker, Postgres)
type: application
version: 0.1.0
appVersion: "0.2.0"
EOF
cat > chart/notes/values.yaml <<'EOF'
# chart/notes/values.yaml – state at end of Day 10
# The chart does not create Secrets: k8s/secrets.sh creates notes-api and notes-db.
existingSecrets:
api: notes-api # key api-key
db: notes-db # keys password, db-url
api:
replicas: 3
image:
repository: notes-api
tag: "" # empty = appVersion from Chart.yaml
resources:
requests: {cpu: 50m, memory: 32Mi}
limits: {memory: 64Mi}
web:
replicas: 2
image:
repository: notes-web
tag: 0.1.0
service:
type: NodePort
nodePort: 30080
resources:
requests: {cpu: 50m, memory: 96Mi}
limits: {memory: 192Mi}
worker:
replicas: 1
interval: 10
image:
repository: notes-worker
tag: 0.1.0
resources:
requests: {cpu: 20m, memory: 64Mi}
limits: {memory: 128Mi}
db:
image:
repository: postgres
tag: 18.6-alpine
storage: 1Gi
storageClassName: "" # empty = default StorageClass of the cluster
resources:
requests: {cpu: 100m, memory: 128Mi}
limits: {memory: 256Mi}
EOFversionis the version of the chart,appVersionthat of the application. An emptyapi.image.tagtakesappVersion– an upgrade of the app is then one line inChart.yaml.- Only what differs between environments becomes a value: replicas, images, resources, Service type, storage. Probes and ports stay fixed in the template.
- The chart does not create the Secrets; it only refers to their names. That way no passwords end up in values and release Secrets (Day 9, Enterprise Note).
Save your progress? Sign up for free
Drill 3: Helpers and the First Template
Recurring blocks go into _helpers.tpl. Helm doesn’t
render files starting with _ as manifests; they only
provide define blocks:
cat > chart/notes/templates/_helpers.tpl <<'EOF'
{{/* chart/notes/templates/_helpers.tpl – state at end of Day 10 */}}
{{/* Labels for a component: include "notes.labels" (dict "ctx" $ "name" "api") */}}
{{- define "notes.labels" -}}
app.kubernetes.io/name: {{ .name }}
app.kubernetes.io/part-of: notes
app.kubernetes.io/instance: {{ .ctx.Release.Name }}
app.kubernetes.io/version: {{ .ctx.Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .ctx.Release.Service }}
helm.sh/chart: {{ printf "%s-%s" .ctx.Chart.Name .ctx.Chart.Version }}
{{- end }}
{{- define "notes.selector" -}}
app.kubernetes.io/name: {{ . }}
{{- end }}
{{/* Image: include "notes.image" (dict "ctx" $ "image" .Values.api.image) */}}
{{- define "notes.image" -}}
{{ .image.repository }}:{{ .image.tag | default .ctx.Chart.AppVersion }}
{{- end }}
{{/* Pod securityContext (restricted); optionally with a fixed UID */}}
{{- define "notes.podSecurity" -}}
serviceAccountName: notes
securityContext:
runAsNonRoot: true
{{- with .uid }}
runAsUser: {{ . }}
runAsGroup: {{ . }}
{{- end }}
{{- with .fsGroup }}
fsGroup: {{ . }}
{{- end }}
seccompProfile:
type: RuntimeDefault
{{- end }}
{{- define "notes.containerSecurity" -}}
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
{{- end }}
{{/* Secrets as files under /etc/notes */}}
{{- define "notes.secretVolume" -}}
- name: secrets
projected:
sources:
- secret:
name: {{ .Values.existingSecrets.api }}
items:
- key: api-key
path: api-key
- secret:
name: {{ .Values.existingSecrets.db }}
items:
- key: db-url
path: db-url
{{- end }}
EOFinclude "name" ARGcalls a block,nindent 4indents it and starts with a line break.{{-and-}}swallow whitespace before and after, respectively.dictbuilds one argument from several values;$is the root context with.Values,.Releaseand.Chart.- The selector stays at
app.kubernetes.io/name– selectors are immutable, and additional labels in them would block every later upgrade.
Now api, built from k8s/api.yaml of Day 8:
cat > chart/notes/templates/api.yaml <<'EOF'
# chart/notes/templates/api.yaml – state at end of Day 10
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
labels:
{{- include "notes.labels" (dict "ctx" $ "name" "api") | nindent 4 }}
spec:
replicas: {{ .Values.api.replicas }}
revisionHistoryLimit: 5
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
{{- include "notes.selector" "api" | nindent 6 }}
template:
metadata:
labels:
{{- include "notes.labels" (dict "ctx" $ "name" "api") | nindent 8 }}
spec:
{{- include "notes.podSecurity" dict | nindent 6 }}
terminationGracePeriodSeconds: 30
containers:
- name: api
image: {{ include "notes.image" (dict "ctx" $ "image" .Values.api.image) }}
{{- include "notes.containerSecurity" . | nindent 10 }}
env:
- name: NOTES_API_KEY_FILE
value: /etc/notes/api-key
- name: NOTES_DB_URL_FILE
value: /etc/notes/db-url
ports:
- containerPort: 8080
resources:
{{- toYaml .Values.api.resources | nindent 12 }}
startupProbe:
httpGet: {path: /healthz, port: 8080}
periodSeconds: 1
failureThreshold: 30
readinessProbe:
httpGet: {path: /healthz, port: 8080}
periodSeconds: 5
livenessProbe:
httpGet: {path: /version, port: 8080}
periodSeconds: 10
failureThreshold: 3
lifecycle:
preStop:
sleep:
seconds: 5
volumeMounts:
- name: secrets
mountPath: /etc/notes
readOnly: true
volumes:
{{- include "notes.secretVolume" . | nindent 8 }}
---
apiVersion: v1
kind: Service
metadata:
name: api
labels:
{{- include "notes.labels" (dict "ctx" $ "name" "api") | nindent 4 }}
spec:
selector:
{{- include "notes.selector" "api" | nindent 4 }}
ports:
- name: http
port: 8080
targetPort: 8080
EOF
helm lint chart/notes
helm template notes chart/notes -n notes -s templates/api.yaml \
| sed -n '/^ spec:/,/^ env:/p'Expected:
==> Linting chart/notes
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed
spec:
serviceAccountName: notes
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
terminationGracePeriodSeconds: 30
containers:
- name: api
image: notes-api:0.2.0
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
env:
Does this match what is running in the cluster?
kubectl diff compares:
helm template notes chart/notes -n notes -s templates/api.yaml | kubectl diff -f - \
| grep -E '^[-+] ' | grep -v generation | sort | uniq -cExpected:
1 + app.kubernetes.io/instance: notes
1 + app.kubernetes.io/managed-by: Helm
1 + app.kubernetes.io/version: 0.2.0
1 + helm.sh/chart: notes-0.1.0
2 + app.kubernetes.io/instance: notes
2 + app.kubernetes.io/managed-by: Helm
2 + app.kubernetes.io/version: 0.2.0
2 + helm.sh/chart: notes-0.1.0
Only labels are added (Deployment, Service, Pod template) – otherwise the template is identical to Day 8. This check pays off every time you convert manifests into templates.
Save your progress? Sign up for free
Drill 4: The Remaining Templates
web, worker, db and the ConfigMap follow the same pattern. Copy them from the companion code and look at the new parts:
C="$LAB/code/tag10/notes/chart/notes"
cp "$C"/templates/{web,worker,db,configmap}.yaml chart/notes/templates/
grep -n -E 'if eq|with \.Values|checksum' chart/notes/templates/*.yaml | cut -c1-88Expected:
chart/notes/templates/db.yaml:71: {{- with .Values.db.storageClassName }}
chart/notes/templates/web.yaml:61: {{- if eq .Values.web.service.type "NodePort" }}
chart/notes/templates/worker.yaml:19: checksum/config: {{ $config | sha256sum }}
if eq … "NodePort"only setsnodePortif the Service type allows it (Day 11 switches toClusterIP).withonly outputs the block if the value isn’t empty; withoutstorageClassName, the PVC takes the default StorageClass.checksum/configis an annotation on worker’s Pod template with the SHA-256 of the rendered ConfigMap. If the ConfigMap changes, the Pod template changes – and worker restarts. Without this trick it would keep the oldINTERVAL, becauseenvFromonly reads at startup.
helm template notes chart/notes -n notes -s templates/worker.yaml | grep checksum
helm template notes chart/notes -n notes | grep -E '^kind:' | sort | uniq -cExpected (abridged):
checksum/config: 8641aae49cf2e02889d1453b8ce37222f6390c4…
1 kind: ConfigMap
3 kind: Deployment
3 kind: Service
1 kind: StatefulSet
Save your progress? Sign up for free
Drill 5: Hook Job, Test and
NOTES.txt
migrate becomes a hook. The head of the file (complete:
code/tag10/notes/chart/notes/templates/migrate-job.yaml):
# chart/notes/templates/migrate-job.yaml – state at end of Day 10
# Hook: runs after install and before every upgrade; the old Job is deleted first.
apiVersion: batch/v1
kind: Job
metadata:
name: migrate
labels:
{{- include "notes.labels" (dict "ctx" $ "name" "migrate") | nindent 4 }}
annotations:
helm.sh/hook: post-install,pre-upgrade
helm.sh/hook-weight: "0"
helm.sh/hook-delete-policy: before-hook-creation
spec:
backoffLimit: 4
# …post-install: after all objects have been created for the first time.pre-upgrade: before every upgrade, i.e. before new api Pods with new schema requirements start.before-hook-creationdeletes the Job from the last run before Helm creates it again – the solution for the immutable Job from Day 8.ttlSecondsAfterFinishedis dropped; the Job stays around until the next run so you can read it.- Hooks are not part of the release’s manifest:
helm uninstallleaves a hook Job in place if no delete policy applies.
In addition, a test Pod that helm test starts, and the
note after installation:
cp "$C"/templates/migrate-job.yaml "$C"/templates/NOTES.txt chart/notes/templates/
cp "$C"/templates/tests/test-api.yaml chart/notes/templates/tests/
cat chart/notes/templates/NOTES.txt
helm template notes chart/notes -s templates/tests/test-api.yaml \
| grep -E -A2 'hook|curl -fsS'
helm template notes chart/notes -s templates/tests/test-api.yaml \
| sed -n '/^spec:/,/^ containers:/p'Expected:
notes {{ .Chart.AppVersion }} ist im Namespace {{ .Release.Namespace }} installiert.
{{- if eq .Values.web.service.type "NodePort" }}
Weboberfläche: http://localhost:{{ .Values.web.service.nodePort }}
{{- end }}
Test: helm test {{ .Release.Name }} -n {{ .Release.Namespace }}
helm.sh/hook: test
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
spec:
serviceAccountName: notes
--
- curl -fsS http://api:8080/healthz && curl -fsS http://web:3000/healthz
resources:
requests: {cpu: 10m, memory: 16Mi}
spec:
serviceAccountName: notes
securityContext:
runAsNonRoot: true
runAsUser: 100
runAsGroup: 100
seccompProfile:
type: RuntimeDefault
restartPolicy: Never
containers:
The test checks both services from the inside.
curlimages/curl has USER curl_user – a name,
so the same trap as with web on Day 8; hence uid 100.
Save your progress? Sign up for free
Drill 6: Validate Values with
values.schema.json
cp "$C"/values.schema.json "$C"/.helmignore chart/notes/
cat chart/notes/.helmignore
grep -A8 '"web": {' chart/notes/values.schema.json
helm template notes chart/notes --set api.replicas=0
helm template notes chart/notes --set web.service.type=LoadBalancer \
--set db.storage=1G
helm lint chart/notes --set worker.interval=zehn | head -3Expected (abridged):
# .helmignore – nicht ins Chart-Paket
.DS_Store
*.tgz
values-*.yaml
"web": {
"type": "object",
"properties": {
"replicas": {"type": "integer", "minimum": 1},
"service": {
"type": "object",
"properties": {
"type": {"enum": ["ClusterIP", "NodePort"]},
"nodePort": {"type": "integer", "minimum": 30000, "maximum": 32767}
Error: values don't meet the specifications of the schema(s) in the following chart(s):
notes:
- at '/api/replicas': minimum: got 0, want 1
Error: values don't meet the specifications of the schema(s) in the following chart(s):
notes:
- at '/web/service/type': value must be one of 'ClusterIP', 'NodePort'
- at '/db/storage': '1G' does not match pattern '^[0-9]+(Mi|Gi)$'
==> Linting chart/notes
[INFO] Chart.yaml: icon is recommended
[ERROR] values.yaml: - at '/worker/interval': got string, want integer
Error: 1 chart(s) linted, 1 chart(s) failed
Helm checks the schema on lint, template,
install and upgrade – before anything reaches
the cluster. 1G would be valid for Kubernetes (gigabytes
instead of gibibytes); the schema enforces the book’s notation here.
.helmignore keeps files out of the chart package, such as
your own values-*.yaml.
Finally, the check against the API server:
helm lint chart/notes
helm template notes chart/notes -n notes | kubectl apply --dry-run=server -f -Expected:
==> Linting chart/notes
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed
configmap/notes-config configured (server dry run)
service/api configured (server dry run)
service/db configured (server dry run)
service/web configured (server dry run)
deployment.apps/api configured (server dry run)
deployment.apps/web configured (server dry run)
deployment.apps/worker configured (server dry run)
statefulset.apps/db configured (server dry run)
pod/notes-test-api created (server dry run)
job.batch/migrate created (server dry run)
If the migrate Job from Day 8 is still in the cluster (TTL 600 s),
the output ends with
The Job "migrate" is invalid: … field is immutable –
harmless: helm template renders the hook like a normal
object, while Helm itself deletes it beforehand via
before-hook-creation.
Save your progress? Sign up for free
Drill 7: The Switch – From
kubectl apply to Helm
First the naive attempt:
curl -s localhost:30080/api/notes | jq -r '.[].text'
helm install notes chart/notes -n notesExpected (abridged, the notes depend on what you created):
Postgres eins
Postgres zwei
Postgres drei
Kontrollpunkt 8
Error: INSTALLATION FAILED: unable to continue with install: ConfigMap "notes-config"
in namespace "notes" exists and cannot be imported into the current release: invalid
ownership metadata; label validation error: missing key
"app.kubernetes.io/managed-by": must be set to "Helm"; annotation validation error: …
Helm doesn’t take over objects it didn’t create itself. So: delete the app objects, keep the platform and the data. The database is briefly gone in the process.
cd k8s && kubectl delete --ignore-not-found -f api.yaml -f web.yaml \
-f worker.yaml -f db.yaml -f migrate.yaml -f config.yaml && cd ..
kubectl wait --for=delete pod --all --timeout 90s >/dev/null
kubectl get pvc,secret,sa
rm k8s/{api,web,worker,db,migrate,config}.yaml && ls k8sExpected (abridged, names, IPs and times will differ on your machine):
deployment.apps "api" deleted from notes namespace
service "api" deleted from notes namespace
deployment.apps "web" deleted from notes namespace
service "web" deleted from notes namespace
deployment.apps "worker" deleted from notes namespace
service "db" deleted from notes namespace
statefulset.apps "db" deleted from notes namespace
configmap "notes-config" deleted from notes namespace
NAME STATUS VOLUME CAPACITY ACCESS MODES …
persistentvolumeclaim/data-db-0 Bound pvc-4464ba68… 1Gi RWO …
NAME TYPE DATA AGE
secret/notes-api Opaque 1 21m
secret/notes-db Opaque 2 21m
NAME AGE
serviceaccount/default 21m
serviceaccount/notes 16m
namespace.yaml
secrets.sh
The PVC survives as on Day 7 (Drill 7).
--ignore-not-found catches the migrate Job in case the TTL
controller has already removed it. Now the chart:
helm install notes chart/notes -n notes --wait
kubectl get pods,jobs
curl -s localhost:30080/api/notes | jq -r '.[].text'Expected (abridged):
NAME: notes
LAST DEPLOYED: Fri Oct 30 14:53:22 2026
NAMESPACE: notes
STATUS: deployed
REVISION: 1
DESCRIPTION: Install complete
NOTES:
notes 0.2.0 ist im Namespace notes installiert.
Weboberfläche: http://localhost:30080
Test: helm test notes -n notes
NAME READY STATUS RESTARTS AGE
pod/api-86c7f84667-gpcwg 1/1 Running 0 15s
pod/api-86c7f84667-ljbg8 1/1 Running 0 15s
pod/api-86c7f84667-snvqt 1/1 Running 1 (11s ago) 15s
pod/db-0 1/1 Running 0 15s
pod/migrate-9kq6k 0/1 Completed 0 5s
pod/web-6c667549-6rtvp 1/1 Running 0 15s
pod/web-6c667549-tslrz 1/1 Running 0 15s
pod/worker-784866df-gr97p 1/1 Running 0 15s
NAME STATUS COMPLETIONS DURATION AGE
job.batch/migrate Complete 1/1 4s 5s
Postgres eins
Postgres zwei
Postgres drei
Kontrollpunkt 8
About 15 s, and the notes are back: the new StatefulSet
db has the same name as the old one, its Pod
db-0 requests data-db-0 – and that already
exists. One api Pod was faster than the database and was restarted once
(Day 7). The hook ran after the other objects
(post-install; with --wait, only once they
were ready).
Tip: Helm 4 knows
--take-ownershipto adopt existing objects. For the switch, the clean cut here is easier to follow – and the immutable Job would have been in the way anyway.
Now the test:
helm test notes -n notes --logsExpected (abridged):
NAME: notes
…
TEST SUITE: notes-test-api
Last Started: Fri Oct 30 14:53:45 2026
Last Completed: Fri Oct 30 14:53:53 2026
Phase: Succeeded
POD LOGS: notes-test-api (curl)
ok
ok
Why does the platform part stay with kubectl? Helm
installs into a namespace that must exist beforehand – together
with PSA labels, quota and ServiceAccount, which apply to all releases
in it. A helm uninstall must never take the namespace, the
quota or the Secrets with it. And Secrets don’t belong in values that
Helm keeps in the release Secret. In operations, the platform part is
the job of the cluster team.
Save your progress? Sign up for free
Drill 8: Upgrade, Hook and Rollback
helm upgrade notes chart/notes -n notes --set api.image.tag=0.1.0 --wait \
| grep -E '^(STATUS|REVISION)'
kubectl get deploy -o wide | cut -c1-88
kubectl exec deploy/web -- wget -qO- http://api:8080/version; echo
kubectl get job migrate \
-o 'custom-columns=NAME:.metadata.name,IMAGE:.spec.template.spec.containers[0].image'Expected (abridged):
STATUS: deployed
REVISION: 2
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELEC…
api 3/3 3 3 92s api notes-api:0.1.0 app.k…
web 2/2 2 2 92s web notes-web:0.1.0 app.k…
worker 1/1 1 1 92s worker notes-worker:0.1.0 app.k…
0.1.0
NAME IMAGE
migrate notes-api:0.1.0
The hook uses the same image as api – migration and code match. Back:
helm rollback notes 1 -n notes --wait
kubectl exec deploy/web -- wget -qO- http://api:8080/version; echo
kubectl get job migrate \
-o 'custom-columns=NAME:.metadata.name,IMAGE:.spec.template.spec.containers[0].image'
helm history notes -n notesExpected (abridged):
Rollback was a success! Happy Helming!
0.2.0
NAME IMAGE
migrate notes-api:0.1.0
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Fri Oct 30 14:53:22 2026 superseded notes-0.1.0 0.2.0 Install complete
2 Fri Oct 30 14:54:33 2026 superseded notes-0.1.0 0.2.0 Upgrade complete
3 Fri Oct 30 14:55:04 2026 deployed notes-0.1.0 0.2.0 Rollback to 1
The Job still shows 0.1.0: a rollback doesn’t start
pre-upgrade hooks (there would be pre-rollback
for that). That is how it should be – a migration only runs forward; a
schema rollback would be a separate, deliberate migration.
You can see that the hook runs before the new Pods with a change that restarts worker:
helm upgrade notes chart/notes -n notes --set worker.interval=20 --wait \
| grep REVISION
kubectl get job migrate \
-o jsonpath='Job migrate: {.status.startTime} bis {.status.completionTime}{"\n"}'
kubectl get pods -l app.kubernetes.io/name=worker -o jsonpath=\
'{range .items[*]}Pod {.metadata.name}: {.metadata.creationTimestamp}{"\n"}{end}'Expected (abridged):
REVISION: 4
Job migrate: 2026-10-30T14:55:28Z bis 2026-10-30T14:55:32Z
Pod worker-6b5455b8cb-w6x7z: 2026-10-30T14:55:33Z
Pod worker-784866df-gr97p: 2026-10-30T14:53:24Z
First the migration (bis means “until”), then the new
worker Pod (the old one is just shutting down). It was restarted by the
checksum/config annotation. Now back to the chart’s values
– and remember the trap from Day 9:
helm upgrade notes chart/notes -n notes --wait | grep REVISION
helm get values notes -n notes
helm upgrade notes chart/notes -n notes --reset-values --wait | grep REVISION
helm get values notes -n notesExpected:
REVISION: 5
USER-SUPPLIED VALUES:
worker:
interval: 20
REVISION: 6
USER-SUPPLIED VALUES:
null
Without --set/-f, Helm takes over the old
values; only --reset-values returns to
values.yaml.
Save your progress? Sign up for free
Checkpoint
helm template notes chart/notes --set api.replicas=0Expected: the schema rejects 0 replicas.
Error: values don't meet the specifications of the schema(s) in the following chart(s):
notes:
- at '/api/replicas': minimum: got 0, want 1
ls k8sExpected: only the platform part remains in the folder
k8s.
namespace.yaml
secrets.sh
helm listExpected: release notes with chart
notes-0.1.0, deployed.
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
notes notes 1 2026-… deployed notes-0.1.0 0.2.0
helm test notesExpected: the test Pod reaches the api,
Phase: Succeeded.
NAME: notes
…
TEST SUITE: notes-test-api
Last Started: …
Last Completed: …
Phase: Succeeded
curl -s localhost:30080/api/notesExpected: the notes from the time before Helm (content differs); the PVC was taken over.
[{"id":"c74b85b6-…","text":"bleibt in Postgres"}]
Challenge
Create a file chart/notes/values-klein.yaml with which
notes runs on a weak laptop with one api replica and one web replica.
Apply it, prove that it doesn’t end up in the chart package, and return
to the default values.
Hint: helm package builds the
.tgz, tar -tzf lists its content.
Solution
cat > chart/notes/values-klein.yaml <<'EOF'
# values-klein.yaml – Challenge Day 10: lean variant for the laptop
api:
replicas: 1
web:
replicas: 1
EOF
helm upgrade notes chart/notes -n notes -f chart/notes/values-klein.yaml --wait \
| grep REVISION
kubectl get deploy
helm package chart/notes -d /tmp/pkg
tar -tzf /tmp/pkg/notes-0.1.0.tgz | grep -c values-klein
rm -rf /tmp/pkg
helm upgrade notes chart/notes -n notes --reset-values --wait | grep REVISION
kubectl get deploy api web
rm chart/notes/values-klein.yamlExpected (abridged):
REVISION: 7
NAME READY UP-TO-DATE AVAILABLE AGE
api 1/1 1 1 3m11s
web 1/1 1 1 3m11s
worker 1/1 1 1 3m11s
Successfully packaged chart and saved it to: /tmp/pkg/notes-0.1.0.tgz
0
REVISION: 8
NAME READY UP-TO-DATE AVAILABLE AGE
api 3/3 3 3 3m23s
web 2/2 2 2 3m23s
The entry values-*.yaml in .helmignore
keeps the file out of the package. Environment values belong to the
environment, not to the chart – the package only contains
values.yaml and values.schema.json.
Save your progress? Sign up for free
Enterprise Note
- Real charts prefix object names with the release name
(
{{ .Release.Name }}-api) so that several releases can run in one namespace. Here the names are fixed so that the PVCdata-db-0is preserved during the switch – one release per namespace. - Version charts (SemVer in
Chart.yaml), push them to an OCI registry withhelm packageandhelm push, and check them in CI withhelm lint,helm template | kubeconformandhelm testin a throwaway cluster. - Database migrations as a hook are convenient, but risky with large
tables: set the timeout (
--timeout) deliberately, write migrations backward-compatible (expand/contract), back up before every upgrade. - Postgres in your own chart is good for learning. In operations, an operator (e.g. CloudNativePG) takes care of backups, failover and upgrades – see “Kubernetes operators hands-on”.
- Secrets come from a secret store (External Secrets, OpenBao) instead of from a script – see “OpenBao secrets hands-on”.