Homework: Templating Fundamentals
Lesson 03 — 3 tasks, self-check criteria
Instructions
Complete each task independently. Use helm template to verify your output at every step. Check your work against the self-check criteria listed under each task.
Task 1: Multi-Service ConfigMap with Pipelines
Create a Helm chart called hw-templating with a ConfigMap template that reads a list of services from values.yaml and generates environment variables for each service.
values.yaml
services:
- name: api-gateway
port: 8080
protocol: https
- name: auth-service
port: 3000
protocol: http
- name: worker
port: 9090
protocol: grpc
defaults:
timeout: "30s"
retries: 3
Requirements
- Use
rangeto iterate over.Values.services - For each service, generate two data entries:
<NAME>_URLand<NAME>_PORT - The name key must be uppercased and have hyphens replaced with underscores (use
upperandreplace) - URL format:
<protocol>://<name>:<port>(useprintfandquote) - Include
.Values.defaults.timeoutand.Values.defaults.retrieswithdefaultfallbacks - All string values must be quoted
Expected output (partial)
data:
API_GATEWAY_URL: "https://api-gateway:8080"
API_GATEWAY_PORT: "8080"
AUTH_SERVICE_URL: "http://auth-service:3000"
AUTH_SERVICE_PORT: "3000"
WORKER_URL: "grpc://worker:9090"
WORKER_PORT: "9090"
DEFAULT_TIMEOUT: "30s"
DEFAULT_RETRIES: "3"
Self-Check
- ✓
helm template test .renders without errors - ✓ All 6 service entries appear with correct uppercased, underscore-separated names
- ✓ URLs follow the
protocol://name:portformat - ✓ All string values are double-quoted in the output
- ✓ Default timeout and retries appear in the data section
Task 2: Conditional Deployment with Resource Toggles
Extend your chart with a Deployment template that uses conditionals, with, and range to handle optional sections.
Add to values.yaml
replicaCount: 3
image:
repository: myapp
tag: "2.1.0"
probes:
liveness:
enabled: true
path: /healthz
port: 8080
readiness:
enabled: true
path: /ready
port: 8080
nodeSelector:
disktype: ssd
region: us-east-1
tolerations:
- key: "dedicated"
operator: "Equal"
value: "gpu"
effect: "NoSchedule"
Requirements
- Use
ifto conditionally include liveness and readiness probes based on.enabled - Use
withfor thenodeSelectorblock (skip entirely if empty) - Use
toYaml | nindentfortolerations - Use
requiredfor.Values.image.tagso the template fails if tag is missing - All trim markers must be correct — no blank lines in rendered output
- Access
$.Release.Namefrom inside awithblock using$
Self-Check
- ✓
helm template test .renders a valid Deployment with both probes - ✓ Setting
--set probes.liveness.enabled=falseremoves the livenessProbe block - ✓ Setting
--set nodeSelector=nullremoves the entire nodeSelector section - ✓ Setting
--set image.tag=""causes a render failure with your custom error message - ✓ No spurious blank lines in the rendered YAML
- ✓ The tolerations section renders correctly indented
Task 3: Release-Aware Annotations with Capabilities
Create a Service template that uses .Release and .Capabilities objects for metadata and version-aware configuration.
Requirements
- Name the Service using
.Release.Name - Add annotations that include:
meta.helm.sh/release-nameset to{{ .Release.Name }}meta.helm.sh/release-namespaceset to{{ .Release.Namespace }}deploy-typeset to"install"or"upgrade"based on.Release.IsInstall(useternary)kube-versionset to{{ .Capabilities.KubeVersion.Version }}
- Use
rangeto iterate over.Values.servicesand create port entries - Each port should have
name,port, andtargetPort
Self-Check
- ✓
helm template test . --namespace productionshowsrelease-namespace: production - ✓ The
deploy-typeannotation renders as"install"(template always simulates an install) - ✓ The
kube-versionannotation contains a valid Kubernetes version string - ✓ All three services from values appear as port entries
- ✓ All annotations are properly quoted
Grading Rubric
| Grade | Criteria |
|---|---|
| Pass | Task 1 complete: ConfigMap renders with correct range iteration, pipelines produce expected URL format, and all values are quoted. helm template produces valid YAML. |
| Merit | Tasks 1 and 2 complete: Deployment includes working conditionals for probes, with for nodeSelector, toYaml | nindent for tolerations, required for image tag, and clean whitespace (no blank lines). |
| Distinction | All three tasks complete: Service uses .Release and .Capabilities objects correctly, ternary function for conditional annotations, and all self-check criteria pass for every task. |
Hints
- Use
helm template test . --debugto see detailed error messages when rendering fails. - The
replacefunction signature is:replace "-" "_" .Values.name(old, new, source) or pipe it:.Values.name | replace "-" "_" - Remember that
withchanges the dot scope — use$to access root-level objects inside awithblock. - The
ternaryfunction:ternary "trueVal" "falseVal" .condition