kubectl kustomize: Command Reference for CI/CD
Render a kustomize overlay to plain YAML for review or apply.
kubectl kustomize builds a kustomize directory and prints the rendered manifests to stdout, without touching the cluster. It is the render half; apply -k is render-and-apply. This reference covers both and a per-environment CI flow.
Common flags and usage
- kustomize <dir>: render an overlay to stdout (no cluster access)
- apply -k <dir>: render and apply in one step
- --enable-helm: allow the helmCharts kustomize feature
- Pipe rendered output into apply, diff, or a policy check
- Overlays under overlays/<env> layer onto a shared base
Example
shell
# Render, preview the diff, then apply the prod overlay
kubectl kustomize overlays/prod > /tmp/rendered.yaml
kubectl diff -f /tmp/rendered.yaml || true
kubectl apply -f /tmp/rendered.yaml --server-sideIn CI
Rendering to stdout first lets you run policy or lint checks on the exact YAML before it reaches the cluster, and feed it to kubectl diff for a review-friendly preview. apply -k is the shorthand when you do not need the intermediate artifact.
Key takeaways
- kustomize renders to stdout; apply -k renders and applies.
- Rendering first lets you lint, diff, and policy-check the exact YAML.
- Per-environment overlays layer onto one shared base.
Related guides
kubectl Cheat Sheet: Commands for Everyday KubernetesA kubectl cheat sheet - get, describe, logs, apply, rollout, debug, and context commands for daily Kubernetes…
kubectl apply: Command Reference for CI/CDReference for kubectl apply: declarative create-or-update from manifests, server-side apply, dry-run validati…
kubectl diff: Command Reference for CI/CDReference for kubectl diff: preview what an apply would change against the live cluster, the meaning of its e…
helm template: Command Reference for CI/CDReference for helm template: render a chart to plain Kubernetes YAML without a cluster, validate with --dry-r…