Cluster operationsLesson 8 of 16
Per-environment deploys with Kustomize (CKA·CKAD)
This relates to "Use Helm and Kustomize to install cluster components" in the CKA Cluster Architecture, Installation and Configuration (25%) domain, and to "Kustomize" in the CKAD Application Deployment (20%) domain. We deploy the same web app with 1 replica in dev and 3 in prod, writing only the differences instead of copying files.
Helm charts, values, revisions and GitOps sync are covered in Helm and GitOps. Here we focus on Kustomize's overlay approach.
Files maintained2 full copies
Prod web—
Command just run-
RequestResponse / reportAppears in a later step
What you will learn
- Why split base and overlays
- Writing only differences with namePrefix, patches and images
- kubectl kustomize vs. kubectl apply -k
- How it differs from Helm
Common exam questions
| Situation | What to do / command | Trap |
|---|---|---|
| Apply an overlay | kubectl apply -k overlays/prod | Use -k, not -f. Pass the folder holding kustomization.yaml, not a file |
| Check the result before applying | kubectl kustomize overlays/prod | This only prints; it does not apply to the cluster |
| Pull base into an overlay | A relative path like ../../base under resources: | Paths are relative to the folder holding kustomization.yaml |
| Change only the image tag | name and newTag under images: | Editing base deployment.yaml directly changes other environments too |
| Change only some fields, like replicas | List a patch file with only those fields under patches: | The patch kind and name must match the base resource to merge |
| Delete what Kustomize deployed | kubectl delete -k overlays/prod | There is no separate uninstall or rollback command like Helm |
Try it yourself
kubectl kustomize overlays/prod # Merged YAML; sends nothing
kubectl kustomize overlays/prod | grep -E 'replicas|image:' # Patch and new tag applied?
kubectl kustomize overlays/dev | grep -E 'name: dev-|namespace:' # namePrefix and namespace
kubectl diff -k overlays/prod # What apply -k would change
Check yourself
Further reading: CNCF certification curriculum · Declarative management of Kubernetes objects using Kustomize · Helm and GitOps