Lesson 17 Multi-Environment Values
Theme:

Homework

Design and implement a production-grade multi-environment deployment pipeline with encrypted secrets.

Submission: For each task, include your complete file tree, all YAML files, and screenshots or terminal output demonstrating successful deployment and verification. Be prepared to explain your directory structure decisions and secret management approach in class.

Task 1 — Production-Grade Directory Structure and Values Layering

Design a multi-environment Helm deployment for a web application with the following requirements:

Your directory structure must follow the layered pattern:

deploy/
  charts/
    webapp/              # your Helm chart
  values/
    base.yaml            # shared defaults
    envs/
      dev.yaml
      staging.yaml
      prod.yaml
    regions/
      us-east.yaml
      eu-west.yaml

The values files must differ across environments and regions on at least these dimensions:

ValueDevStagingProd (us-east)Prod (eu-west)
Replicas1253
Image taglatestv2.0.0-rc1v2.0.0
Ingress hostdev.localstaging.example.comus.example.comeu.example.com
Log leveldebuginfowarn
CPU request50m200m500m500m

Demonstrate the layering by rendering each variant and verifying the merge order:

# Dev (base + dev)
helm template webapp deploy/charts/webapp \
  -f deploy/values/base.yaml \
  -f deploy/values/envs/dev.yaml

# Prod US-East (base + prod + us-east)
helm template webapp deploy/charts/webapp \
  -f deploy/values/base.yaml \
  -f deploy/values/envs/prod.yaml \
  -f deploy/values/regions/us-east.yaml

# Prod EU-West (base + prod + eu-west)
helm template webapp deploy/charts/webapp \
  -f deploy/values/base.yaml \
  -f deploy/values/envs/prod.yaml \
  -f deploy/values/regions/eu-west.yaml

Self-check

Task 2 — Helmfile with Encrypted Secrets

Build a complete Helmfile configuration that manages all environments from Task 1, including encrypted secrets. Your helmfile.yaml must:

  1. Define dev, staging, prod-us-east, and prod-eu-west as named environments
  2. Compose the correct values file layers for each environment (base + env + optional region)
  3. Include a SOPS-encrypted secrets file per environment under deploy/values/secrets/
  4. Use the secrets: field in Helmfile releases for automatic decryption

Your secrets files must contain at least:

Example Helmfile structure:

# helmfile.yaml
environments:
  dev:
    values:
      - namespace: dev
  staging:
    values:
      - namespace: staging
  prod-us-east:
    values:
      - namespace: prod
      - region: us-east
  prod-eu-west:
    values:
      - namespace: prod
      - region: eu-west

---

releases:
  - name: webapp-{{ .Environment.Name }}
    chart: deploy/charts/webapp
    namespace: {{ .Values.namespace }}
    createNamespace: true
    values:
      - deploy/values/base.yaml
      - deploy/values/envs/{{ ... }}.yaml   # your logic here
      {{- if .Values.region }}
      - deploy/values/regions/{{ .Values.region }}.yaml
      {{- end }}
    secrets:
      - deploy/values/secrets/{{ .Environment.Name }}.yaml

Demonstrate all of the following commands:

# Preview what each environment will deploy
helmfile -e dev template
helmfile -e prod-us-east template

# Show the diff before applying
helmfile -e staging diff

# Deploy
helmfile -e dev apply

# List managed releases
helmfile -e dev list

# Clean up
helmfile -e dev destroy

Self-check

Task 3 — CI Pipeline Design

Write a GitHub Actions workflow (or equivalent CI configuration) that implements the following multi-environment deployment pipeline:

  1. On push to any branch: run helmfile -e dev template and helm lint for all environments to validate the chart
  2. On merge to main: automatically deploy to staging with helmfile -e staging apply
  3. On Git tag (v*): deploy to both production regions with manual approval gates

The workflow must handle secrets correctly:

Provide the complete .github/workflows/deploy.yaml file and explain each step in inline comments.

Self-check

Grading Rubric

Criterion Points Requirements
Task 1 — Directory structure and layering 30 Layered pattern with envs/ and regions/; all 5 variants render correctly; region files are minimal overlays; helm lint passes for all
Task 2 — Helmfile with encrypted secrets 40 Four environments defined; correct values composition per environment; SOPS encryption working; helmfile apply deploys successfully; secrets verified in cluster
Task 3 — CI pipeline design 20 Three triggers; validation on push; auto-deploy staging; manual approval for prod; correct secret handling; cleanup step
Code quality and documentation 10 Clean YAML formatting; meaningful comments in Helmfile and workflow; .gitignore excludes private keys; clear README or inline explanation