Lesson 10 Helm Chart for the Two Services
Theme:
Lesson 10 · Slide 1

Lesson 10 — Helm Chart for the Two Services

Stop copy-pasting YAML. Package, template, version, and parametrise the whole app.

Cloud DevOps Module 4 Helm Kubernetes
Lesson 10 · Slide 2

The L09 → L10 motivation

Where L09 left us

8 YAML files with replicas and image tags baked in. Different envs would need forks of every file.

What Helm gives us

One chart, three values files (dev / stage / prod), helm upgrade per env, version history, and atomic rollback.

“Raw YAML scales to one env. Helm is what you use for two or more.”

Lesson 10 · Slide 3

What Helm is (and isn’t)

Lesson 10 · Slide 4

Chart anatomy

helm/
  Chart.yaml             # metadata: name, version, appVersion
  values.yaml            # default values
  values-dev.yaml        # dev overrides (1 replica, kind cluster)
  values-stage.yaml      # stage overrides
  values-prod.yaml       # prod overrides (3 replicas, real ingress)
  templates/
    _helpers.tpl         # named-template helpers
    api-deployment.yaml
    api-service.yaml
    worker-deployment.yaml
    postgres-statefulset.yaml
    configmap.yaml
    secret.yaml          # only when .Values.secrets.inChart=true
    NOTES.txt            # post-install message

Every file in templates/ is a Go template rendered against .Values, .Release, and .Chart.

Lesson 10 · Slide 5

Templating in 4 idioms

Value reference

image: {{ .Values.api.image }}:{{ .Values.api.tag }}

Default fallback

replicas: {{ .Values.api.replicas | default 2 }}

Conditional

{{- if .Values.api.hpa.enabled }}
...
{{- end }}

Named template

{{- include "shortener.labels" . | nindent 4 }}
Lesson 10 · Slide 6

values.yaml design

image:
  repository: ghcr.io/REPLACE_ME
  pullPolicy: IfNotPresent
api:
  replicas: 2
  tag: "0.4.0"
  probes:
    enabled: true
worker:
  replicas: 1
  tag: "0.4.0"
postgres:
  enabled: true   # set false in stage/prod (managed DB)
  storage: 1Gi
ingress:
  enabled: false  # turned on in L11

Top-level keys are component-shaped (api, worker, postgres, ingress); each component owns its own knobs.

Lesson 10 · Slide 7

Per-env overrides

# values-dev.yaml
api: {replicas: 1}
worker: {replicas: 1}
postgres: {enabled: true}
# values-prod.yaml
api: {replicas: 3, tag: "0.4.5"}
worker: {replicas: 2, tag: "0.4.5"}
postgres: {enabled: false}   # managed RDS
ingress: {enabled: true, host: "s.example.com"}

helm upgrade --install shortener . -f values.yaml -f values-prod.yaml — last file wins on conflicts.

Lesson 10 · Slide 8

Render, lint, dry-run

helm lint sample-app/helm/
helm template sample-app/helm/ -f values-dev.yaml | kubectl apply --dry-run=client -f -
helm install shortener sample-app/helm/ -f values-dev.yaml --dry-run --debug

Three commands cover schema validation, manifest rendering, and pre-flight without touching the cluster.

Lesson 10 · Slide 9

helm upgrade --install is your friend

The idempotent install-or-upgrade command. Pair it with --atomic so a failed upgrade rolls back automatically. Pair it with --wait so the command blocks until all pods are Ready. The canonical production deploy:

helm upgrade --install shortener . \
  -f values-stage.yaml \
  --atomic --wait --timeout 5m \
  --namespace shortener --create-namespace

No separate helm install on first run; no manual rollback step on failure — one command for every deploy.

Lesson 10 · Slide 10

Rollback and history

helm history shortener -n shortener
helm rollback shortener 3 -n shortener

Revision numbers track every upgrade; rolling back is a single command and works even mid-incident. The rollback itself becomes a new revision — your history is always append-only.

Lesson 10 · Slide 11

Chart-testing in CI

ct lint && ct install (from helm/chart-testing) runs helm lint, schema validation, and an actual install against a kind cluster spun up in the workflow. The GitHub Actions snippet that wires it up:

- uses: helm/kind-action@v1
- uses: helm/chart-testing-action@v2
- run: ct lint --chart-dirs sample-app --charts sample-app/helm
- run: ct install --chart-dirs sample-app --charts sample-app/helm

Pin chart-testing in CI to gate every PR that touches helm/.

Lesson 10 · Slide 12

What we’ll build today

Lesson 10 · Slide 13

Recap & what’s next

Coming up: Lesson 11 — expose the chart on a real domain with Ingress + cert-manager + ExternalDNS.
1 / ?