Lesson 07 Deployments & StatefulSets
Theme:

Homework

Lesson 07 — Deployments & StatefulSets

Instructions

Complete all three tasks. Use helm template to verify rendered output before installing. Use the grading table at the bottom to self-assess your work.

Task 1 — Blue-Green Deployment Toggle

Extend your Deployment template to support both RollingUpdate and Recreate strategies, selectable from values.yaml. Add a conditional block so that rollingUpdate parameters are only rendered when the strategy type is RollingUpdate.

Requirements

Verification

# Should show rollingUpdate parameters
helm template . --set strategy.type=RollingUpdate | grep -A 3 rollingUpdate

# Should NOT show rollingUpdate parameters
helm template . --set strategy.type=Recreate | grep rollingUpdate
# (expect no output)

Task 2 — StatefulSet with Configurable Storage

Create a StatefulSet template for a PostgreSQL workload with the following features:

Provide a values.yaml snippet

postgresql:
  replicas: 3
  image: postgres:16-alpine
  storageClass: standard
  storageSize: 5Gi
  pdb:
    minAvailable: 1

Verification

# Rendered output should contain volumeClaimTemplates
helm template . | grep -A 10 volumeClaimTemplates

# PDB should reference correct selector labels
helm template . | grep -A 8 "kind: PodDisruptionBudget"

Task 3 — Multi-Environment Values Override

Create three values files for different environments. Each must configure the Deployment and (optionally) the StatefulSet with appropriate settings:

FileReplicasResourcesStrategyPDB
values-dev.yaml 1 requests: 50m CPU, 64Mi memory; no limits Recreate disabled
values-staging.yaml 2 requests: 100m CPU, 128Mi; limits: 250m CPU, 256Mi RollingUpdate (maxSurge: 1, maxUnavailable: 1) maxUnavailable: 1
values-prod.yaml 5 requests: 250m CPU, 256Mi; limits: 1 CPU, 1Gi RollingUpdate (maxSurge: 2, maxUnavailable: 0) minAvailable: 4

Production must also include:

Verification

# Compare rendered output across environments
helm template . -f values-dev.yaml | grep replicas
helm template . -f values-staging.yaml | grep replicas
helm template . -f values-prod.yaml | grep -A 4 topologySpreadConstraints

Grading Rubric

CriterionPointsHow to Verify
Task 1: Strategy toggle works — rollingUpdate block absent with Recreate 10 helm template . --set strategy.type=Recreate has no rollingUpdate key
Task 1: Init container conditional renders correctly 5 helm template . --set initContainers.migrate.enabled=true shows init container
Task 1: Defaults applied for maxSurge/maxUnavailable when not set 5 helm template . shows default values in rollingUpdate block
Task 2: StatefulSet renders with volumeClaimTemplates 10 Rendered YAML contains volumeClaimTemplates with correct storage class and size
Task 2: Headless Service has clusterIP: None 5 helm template . shows headless service
Task 2: Env vars sourced from Secret and ConfigMap 5 Rendered pod spec contains secretKeyRef and configMapKeyRef
Task 2: PDB with minAvailable: 1 5 helm template . shows PDB with minAvailable: 1
Task 2: Startup probe on TCP 5432 5 Rendered StatefulSet contains tcpSocket startup probe
Task 3: Three environment files produce correct replica counts 10 Template output shows 1, 2, and 5 replicas respectively
Task 3: Production includes topology spread with zone constraint 10 helm template . -f values-prod.yaml shows topologySpreadConstraints
Task 3: Resource differences across environments are correct 10 Diff rendered output for each environment
Task 3: PDB disabled in dev, configured in staging/prod 5 Dev output has no PDB; staging/prod have correct PDB values
All templates pass helm lint 10 helm lint . and helm lint . -f values-prod.yaml report no errors
Total 95
Bonus: Templates install successfully in a live cluster +5 helm install succeeds and pods reach Ready state

Submission

Ensure all files pass helm lint without errors. Run helm template . -f values-prod.yaml and review the full rendered output to confirm correctness before submitting.