DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

Kubernetes & HelmLesson 16 of 16
Your progress · 0%
On this page
  1. What you're building
  2. The chart
  3. The security baseline
  4. Dev and prod from one chart
  5. Track A: kind (free)
  6. Track B: EKS (optional)
  7. Ship it
↖ Course roadmap
Lesson 16 · Capstone project

Capstone: a production-ready release of shop-web

Everything from the course in one Helm chart: config, probes, limits, security, a disruption budget, a network policy and autoscaling, with dev and prod values and a zero-downtime release.

60 min read · intermediate · hands-on

By the end of this lesson you'll be able to

0 of 5 complete
Lab status

Verified: helm lint and helm template of the chart for dev and prod, with Helm 4.3.1. The output shown is real.
Code walkthrough: the install, release and rollback on kind. The steps are the same ones lessons 4 to 14 ran for real on EKS, but this exact chart hasn't been run end to end on a cluster yet. Expect to fix small things, as you would at work.
Cloud lab: Track B on EKS is optional and costs money while it runs.

Fifteen lessons, fifteen separate pieces. In a real job they arrive together: someone asks you to "put shop-web on Kubernetes properly" and expects probes, limits, config, security, safe releases and autoscaling in one deliverable. This capstone is that deliverable: one Helm chart, two environments, and evidence that a release doesn't drop a single request.

What you're building

  • One chart (shop) starting from helm create (lesson 13), with every production setting from the course.
  • Two values files: values-dev.yaml (1 replica, cheap) and values-prod.yaml (autoscaling 3 to 6).
  • Evidence: a client calling the app 5 times a second through a release, a failed release rolled back, and a privileged Pod refused.

The app is shop-web from lesson 2: /api returns its version, /healthz is the probe endpoint, and the v3-broken image crashes on start.

The chart

shop/
├── Chart.yaml            # name shop, version 1.0.0, appVersion v1
├── values.yaml           # defaults: every setting below
├── values-dev.yaml
├── values-prod.yaml
└── templates/
    ├── configmap.yaml    # new: non-secret settings
    ├── deployment.yaml   # + envFrom, strategy, config checksum, topology spread
    ├── hpa.yaml
    ├── ingress.yaml
    ├── networkpolicy.yaml  # new
    ├── pdb.yaml          # new
    ├── service.yaml
    ├── serviceaccount.yaml
    └── tests/test-connection.yaml

Each default in values.yaml maps to a lesson:

# values.yaml (the production settings)
config: # lesson 6: settings in a ConfigMap, not baked into the image
  GREETING: 'Hello from the capstone'
  APP_COLOR: '#4f7a65'

resources: # lesson 7: requests for scheduling, a memory limit against leaks
  requests:
    cpu: 100m
    memory: 64Mi
  limits:
    memory: 128Mi

strategy: # lesson 14: never drop below full capacity during a release
  type: RollingUpdate
  rollingUpdate:
    maxSurge: 1
    maxUnavailable: 0

readinessProbe: # lesson 4: no traffic until /healthz answers
  httpGet:
    path: /healthz
    port: http
  periodSeconds: 2

podDisruptionBudget: # lesson 11: drains take one Pod at a time
  enabled: true
  maxUnavailable: 1

networkPolicy: # lesson 8: only role=frontend Pods and the ingress controller get in
  enabled: true
  ingressNamespace: ingress-nginx

topologySpread: true # lesson 11: spread replicas across nodes

Three template changes are worth reading closely. The Deployment loads the ConfigMap as environment variables and carries a checksum of it, so changing a setting rolls the Pods:

# templates/deployment.yaml (excerpt)
template:
  metadata:
    annotations:
      # Restart Pods when the ConfigMap changes.
      checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
  spec:
    containers:
      - name: shop
        envFrom:
          - configMapRef:
              name: {{ include "shop.fullname" . }}

Without that annotation, a new greeting would update the ConfigMap and change nothing: Pods read environment variables once, at start.

The NetworkPolicy allows two sources and nothing else:

# templates/networkpolicy.yaml (excerpt)
ingress:
  - from:
      - podSelector:
          matchLabels:
            role: frontend
      - namespaceSelector:
          matchLabels:
            kubernetes.io/metadata.name: {{ .Values.networkPolicy.ingressNamespace }}
    ports:
      - port: http

Lesson 8's lab removed its policies because a default-deny broke the load balancer. Allowing the ingress controller's namespace here is the fix. And helm test runs a Pod too, so tests/test-connection.yaml carries role: frontend, or the chart's own test would time out against its own policy.

The security baseline

The chart passes the restricted Pod Security standard from lesson 8:

# values.yaml (security)
serviceAccount:
  automount: false # the app never calls the Kubernetes API
podSecurityContext:
  runAsNonRoot: true
  runAsUser: 10001
  seccompProfile:
    type: RuntimeDefault
securityContext:
  allowPrivilegeEscalation: false
  readOnlyRootFilesystem: true
  capabilities:
    drop: ['ALL']

readOnlyRootFilesystem works because shop-web writes nothing to disk. An app that needs a scratch directory gets an emptyDir volume mounted there instead of a writable image. Not mounting the service account token means a compromised container has no credentials for the cluster API.

Dev and prod from one chart

Each environment file holds only what differs:

# values-dev.yaml
replicaCount: 1
config:
  GREETING: 'Hello from dev'
podDisruptionBudget:
  enabled: false # one replica + a budget = every drain blocked
# values-prod.yaml
config:
  GREETING: 'Hello from production'
autoscaling:
  enabled: true
  minReplicas: 3
  maxReplicas: 6

Check what each renders before installing anything:

$ helm lint ./shop -f shop/values-prod.yaml
==> Linting ./shop
[INFO] Chart.yaml: icon is recommended

1 chart(s) linted, 0 chart(s) failed
$ helm template shop ./shop -f shop/values-dev.yaml | grep '^kind:' | sort | uniq -c
      1 kind: ConfigMap
      1 kind: Deployment
      1 kind: NetworkPolicy
      1 kind: Pod
      1 kind: Service
      1 kind: ServiceAccount
$ helm template shop ./shop -f shop/values-prod.yaml | grep '^kind:' | sort | uniq -c
      1 kind: ConfigMap
      1 kind: Deployment
      1 kind: HorizontalPodAutoscaler
      1 kind: NetworkPolicy
      1 kind: Pod
      1 kind: PodDisruptionBudget
      1 kind: Service
      1 kind: ServiceAccount
$ helm template shop ./shop -f shop/values-dev.yaml | grep -E 'replicas:|GREETING'
  GREETING: Hello from dev
  replicas: 1
$ helm template shop ./shop -f shop/values-prod.yaml | grep -E 'replicas:|minReplicas|maxReplicas|GREETING'
  GREETING: Hello from production
  minReplicas: 3
  maxReplicas: 6
helm template shop ./shop -f shop/values-dev.yaml | grep '^kind:' | sort | uniq -c
  • |pipe: send output to the next command
  • grepfind lines that match a pattern
  • sortsort lines
  • uniqdrop repeated lines
  • -ccount each one

(The Pod is the helm test hook.) Prod has two extra objects, the HPA and the PDB, and no replicas: line: when autoscaling is on, the chart leaves the count to the HPA. A fixed value would reset the HPA's choice on every helm upgrade. The rendered Deployment also shows the release strategy and security settings landed where they should:

$ helm template shop ./shop -f shop/values-prod.yaml --show-only templates/deployment.yaml | grep -A3 -E 'strategy:|checksum|securityContext:'
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
--
        checksum/config: c491dc2f7930514e108f0bebc5bb1b32d6a54381aadd5477db6658aeaf1f4b27
...
      securityContext:
        runAsNonRoot: true
        runAsUser: 10001
        seccompProfile:
helm template shop ./shop -f shop/values-prod.yaml --show-only templates/deployment.yaml | grep -A3 -E 'strategy:|checksum|securityContext:'
  • |pipe: send output to the next command
  • grepfind lines that match a pattern

Track A: kind (free)

A three-node kind cluster (one control plane, two workers, so the disruption budget and topology spread have somewhere to move Pods):

# kind.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: capstone
nodes:
  - role: control-plane
  - role: worker
  - role: worker
$ kind create cluster --config kind.yaml
$ docker build -t shop-web:v1 --build-arg APP_VERSION=v1 ./app
$ docker build -t shop-web:v2 --build-arg APP_VERSION=v2 ./app
$ docker build -t shop-web:v3-broken -f ./app/Dockerfile.broken ./app
$ docker pull busybox:1.37
$ kind load docker-image shop-web:v1 shop-web:v2 shop-web:v3-broken busybox:1.37 --name capstone
kind create cluster --config kind.yaml
  • kindKubernetes in Docker: local clusters
  • createcreate
docker build -t shop-web:v1 --build-arg APP_VERSION=v1 ./app
  • dockerbuild and run containers
  • buildbuild an image from a Dockerfile
  • -t shop-web:v1name and tag the image
  • --build-arg APP_VERSION=v1a build argument (visible in history)
docker build -t shop-web:v2 --build-arg APP_VERSION=v2 ./app
  • -t shop-web:v2name and tag the image
  • --build-arg APP_VERSION=v2a build argument (visible in history)
docker build -t shop-web:v3-broken -f ./app/Dockerfile.broken ./app
  • -t shop-web:v3-brokenname and tag the image
  • -fwhich Dockerfile
docker pull busybox:1.37
  • pulldownload an image
  • busybox:1.37the image
kind load docker-image shop-web:v1 shop-web:v2 shop-web:v3-broken busybox:1.37 --name capstone
  • --namecluster name

Pull busybox first: kind load copies images from your local Docker and fails the whole command if one is missing. The chart's pullPolicy: IfNotPresent then uses the loaded images instead of trying a registry.

The autoscaler needs metrics-server, which on kind needs --kubelet-insecure-tls because kind's kubelets use self-signed certificates:

$ helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
$ helm install metrics-server metrics-server/metrics-server -n kube-system --set "args={--kubelet-insecure-tls}" --wait
$ kubectl create namespace shop
$ kubectl label namespace shop pod-security.kubernetes.io/enforce=restricted
$ helm install shop ./shop -n shop -f shop/values-prod.yaml --wait --timeout 4m
$ kubectl get deploy,svc,hpa,pdb,networkpolicy -n shop
$ helm test shop -n shop
kubectl create namespace shop
  • kubectltalk to a Kubernetes cluster
  • createcreate an object
kubectl get deploy,svc,hpa,pdb,networkpolicy -n shop
  • getlist objects
  • -nin this namespace

You should see 3 ready Pods spread over both workers, the HPA reading CPU, and helm test passing.

Prove a zero-downtime release

probe.yaml is a Pod labelled role=frontend that calls /api five times a second for 75 seconds and prints the version it got, or FAIL:

# probe.yaml (the loop)
command:
  - sh
  - -c
  - |
    for i in $(seq 1 375); do
      if r=$(wget -qO- -T 2 http://shop/api); then
        echo "$r" | grep -o '"version": "v[0-9]"'
      else
        echo FAIL
      fi
      sleep 0.2
    done

Start it, release v2 while it runs, and count:

$ kubectl apply -n shop -f probe.yaml && kubectl wait -n shop --for=condition=Ready pod/probe
$ helm upgrade shop ./shop -n shop -f shop/values-prod.yaml --set image.tag=v2 --wait
$ kubectl wait -n shop --for=jsonpath='{.status.phase}'=Succeeded pod/probe --timeout=120s
$ kubectl logs -n shop probe | sort | uniq -c
kubectl apply -n shop -f probe.yaml && kubectl wait -n shop --for=condition=Ready pod/probe
  • kubectltalk to a Kubernetes cluster
  • applycreate or update from a file
  • -nin this namespace
  • -ffrom this file
  • &&run the next command only if this one worked
kubectl logs -n shop probe | sort | uniq -c
  • logsshow a Pod’s output
  • |pipe: send output to the next command
  • sortsort lines
  • uniqdrop repeated lines
  • -ccount each one

The goal: v1 lines, then v2 lines, and zero FAIL. If you see failures, the usual causes are a readiness probe that passes before the app can serve, or Pods killed before the Service stops sending them traffic (add a short preStop sleep). Finding and fixing that is the most realistic part of this project.

Then the bad release and the rollback, as in lesson 13:

$ helm upgrade shop ./shop -n shop -f shop/values-prod.yaml --set image.tag=v3-broken --wait --timeout 60s
$ helm rollback shop 2 -n shop --wait
$ helm history shop -n shop

The upgrade should fail with the v2 Pods still serving (maxUnavailable: 0 guarantees it), and the rollback becomes revision 4.

Finish with the other checks: drain a worker (kubectl drain <node> --ignore-daemonsets) and watch the PDB let Pods move one at a time; call the app from a Pod without role=frontend and see it time out; and try a privileged Pod in the namespace and see it refused. run.sh in the capstone folder runs all of it in order. When you're done:

$ kind delete cluster --name capstone
kind delete cluster --name capstone
  • kindKubernetes in Docker: local clusters
  • deletedelete
  • --namecluster name

Track B: EKS (optional)

The same chart runs on the EKS cluster from lesson 3 with three changes:

  1. Images come from ECR: --set image.repository=<account>.dkr.ecr.<region>.amazonaws.com/shop-web.
  2. Traffic comes through the AWS Load Balancer Controller (lesson 5): enable the chart's Ingress with className: alb and the alb.ingress.kubernetes.io/scheme and target-type: ip annotations, and set networkPolicy.ingressNamespace so the policy allows it. With target-type: ip the ALB connects straight to Pod IPs from the VPC, so check your policy allows that path too.
  3. metrics-server is the EKS add-on, so skip the Helm install.

EKS costs about $0.10 an hour for the control plane plus the nodes and the load balancer (lesson 3 has the prices). Run it for the evidence you need, then terraform destroy, and check the console for leftover load balancers and volumes.

Ship it

Put the chart, kind.yaml, probe.yaml and run.sh in a public repository with a README that shows the probe counts and the rollback history. Add a CI job that runs helm lint and helm template for both values files on every pull request: it's cheap, catches most chart mistakes, and is exactly what lesson 13 recommended.

⌘
Mini mission

Release shop-web with zero failed requests

Build the chart, install it on kind with the prod values into a restricted namespace, release v2 while probe.yaml runs, roll back a v3-broken release, and publish the project with the evidence in its README.

Input: The shop chart, kind.yaml, probe.yaml and the shop-web imagesOutput: A public repository with the chart, the probe counts (0 FAIL) and helm history
Reveal one safe solution
$ helm lint ./shop -f shop/values-prod.yaml
$ ./run.sh                      # create the cluster, build, load, install, release, roll back, drain
$ kubectl logs -n shop probe | sort | uniq -c > evidence.txt
$ helm history shop -n shop >> evidence.txt
$ kind delete cluster --name capstone
kubectl logs -n shop probe | sort | uniq -c > evidence.txt
  • kubectltalk to a Kubernetes cluster
  • logsshow a Pod’s output
  • -nin this namespace
  • |pipe: send output to the next command
  • sortsort lines
  • uniqdrop repeated lines
  • -ccount each one
  • >write output to a file, replacing it
helm history shop -n shop >> evidence.txt
  • >>append output to a file
kind delete cluster --name capstone
  • kindKubernetes in Docker: local clusters
  • deletedelete
  • --namecluster name

If uniq -c shows any FAIL lines, don't hide them: find the cause, fix it, and write what you changed in the README. That story is worth more in an interview than a clean run.

Try it yourself

0 of 5 steps done

Run each task in your own account or terminal, then tick it off.

Knowledge check

Quick check

Question 1 of 4

Why is maxUnavailable set to 0 in the chart's rolling update strategy?

Go deeper

Official reading for this lesson

  • DocsHelm chart best practicesHelm ↗
  • DocsProduction best practices checklistKubernetes ↗
  • Docskind quick startkind ↗
  • DocsEKS best practices guideAWS Docs ↗

Or get every quiz answer right and it completes itself.

Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.

← PreviousAdvanced: inside the cluster, CRDs and many clustersUp nextBack to the course roadmap