Skip to main content
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-
overlays/baseshared manifestsdevdev differencesprodprod differenceskustomizebuilt into kubectlOutput YAMLmerged resultDev envnamespace devProd envnamespace prodfull copyfull copy
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​

SituationWhat to do / commandTrap
Apply an overlaykubectl apply -k overlays/prodUse -k, not -f. Pass the folder holding kustomization.yaml, not a file
Check the result before applyingkubectl kustomize overlays/prodThis only prints; it does not apply to the cluster
Pull base into an overlayA relative path like ../../base under resources:Paths are relative to the folder holding kustomization.yaml
Change only the image tagname and newTag under images:Editing base deployment.yaml directly changes other environments too
Change only some fields, like replicasList a patch file with only those fields under patches:The patch kind and name must match the base resource to merge
Delete what Kustomize deployedkubectl delete -k overlays/prodThere 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

  1. You need prod to run 3 replicas while dev keeps 1. Where do you make the change?
  2. You run kubectl kustomize overlays/prod, but nothing changes in the cluster. Why?
  3. A bad image tag went out with kubectl apply -k overlays/prod. How do you roll back?

Further reading: CNCF certification curriculum · Declarative management of Kubernetes objects using Kustomize · Helm and GitOps