Lesson 13 Helpers & Named Templates
Theme:

Homework

Three tasks to master _helpers.tpl, define/include, scope control, and DRY patterns in Helm charts.

Setup: Start each task with a fresh chart created via helm create. All tasks can be completed locally using helm template -- no running cluster is required, though you may optionally install to verify.

Tasks

Task 1 — Multi-Image Helper with Registry Support

Create a Helm chart for a microservice that has three containers: app, sidecar-proxy, and log-collector. Each container uses a different image.

Self-check

Task 2 — Scope, the Dot, and $ in Range Loops

Create a chart that generates a ConfigMap per environment using range over a list in values, while still accessing root-level helpers inside the loop.

Self-check

Task 3 — DRY Probes and Annotations via Helpers

Build a chart with a Deployment and a CronJob that share the same health-probe configuration and annotation set.

Self-check

Grading Rubric

Criterion Excellent Satisfactory Needs Work
Helper Design Helpers are generic, accept dicts or scoped data, and produce clean YAML with no trailing whitespace Helpers work but are tightly coupled to specific values paths Helpers are missing or use template instead of include
Scope & Dot Correctly uses $ inside range/with; can explain why it is needed; passes custom dicts to helpers Uses $ correctly but cannot explain the mechanism Scope errors in rendered output; labels or names missing inside loops
nindent Usage All helper invocations use include piped to nindent at the correct level; YAML is valid Indentation mostly correct with minor cosmetic issues Broken YAML due to incorrect indentation; uses template with attempted pipe
DRY Principle No duplicated YAML blocks; every repeated fragment is extracted into a named template Most duplication removed but one or two blocks remain inlined Significant copy-paste between templates; helpers exist but are unused
Validation helm lint passes with zero warnings; helm template output is valid Kubernetes YAML Lint passes but template output has minor issues (e.g., empty values) Lint errors or template rendering failures

Tip: When debugging helpers, use helm template . --debug to see the full rendering trace. If indentation looks wrong, double-check your nindent value -- it counts from the start of the line, not from the current cursor position. A quick way to verify: pipe template output through kubectl apply --dry-run=client -f - to catch YAML structure errors.