CKAD — Kustomize Transformations
Common Kustomize Transformations
Kustomize provides many built-in transformations you can apply through kustomization.yaml:
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
- service.yaml
# Add a prefix to all resource names
namePrefix: myapp-
# Add a suffix to all resource names
nameSuffix: -v2
# Set namespace for all resources
namespace: production
# Add labels to all resources
commonLabels:
team: backend
env: prod
# Add annotations to all resources
commonAnnotations:
managed-by: kustomize
# Change the image tag
images:
- name: myapp
newTag: v3.0
newName: registry.example.com/myapp
# Generate ConfigMaps
configMapGenerator:
- name: app-config
literals:
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
# Generate Secrets
secretGenerator:
- name: db-credentials
literals:
- username=admin
- password=secret123
Transformation Summary
| Transformation | What It Does |
|---|---|
namePrefix |
Adds prefix to all resource names |
nameSuffix |
Adds suffix to all resource names |
namespace |
Sets namespace for all resources |
commonLabels |
Adds labels to all resources and selectors |
commonAnnotations |
Adds annotations to all resources |
images |
Overrides image names and tags |
configMapGenerator |
Creates ConfigMaps from literals or files |
secretGenerator |
Creates Secrets from literals or files |
Strategic Merge Patches
For more complex modifications, use strategic merge patches. You write a partial YAML that gets merged with the base:
# overlays/prod/increase-resources.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
template:
spec:
containers:
- name: api
resources:
requests:
cpu: 500m
memory: 512Mi
limits:
cpu: "1"
memory: 1Gi
# overlays/prod/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
patches:
- path: increase-resources.yaml
The patch is merged with the base resource by matching kind + metadata.name. Only the fields you specify are changed — everything else stays the same.
Helm vs Kustomize
Both tools help manage Kubernetes manifests, but they take different approaches:
| Feature | Helm | Kustomize |
|---|---|---|
| Approach | Templating | Patching |
| Installation | Separate binary | Built into kubectl |
| Complexity | Higher (Go templates) | Lower (YAML patches) |
| Package sharing | Charts + repositories | Directories (git) |
| Rollback | Built-in (helm rollback) |
Manual (re-apply old overlay) |
| Best for | Third-party apps, complex deployments | Environment-specific customization |
| CKAD focus | Installing and managing charts | Customizing with overlays |
Exam tip: The CKAD may test both Helm and Kustomize. For Helm, focus on helm install, helm upgrade, helm rollback, and helm uninstall. For Kustomize, focus on kubectl apply -k and understanding kustomization.yaml.
Next: Hands-On Lab