kubectl annotate: Command Reference for CI/CD
Attach metadata that tools read but selectors ignore.
kubectl annotate sets free-form key/value metadata that controllers and tooling read but selectors never match. Its headline CI use is the change-cause annotation that makes rollout history meaningful. This reference covers the syntax and limits.
Common flags and usage
- annotate <res> <name> k=v: add an annotation
- annotate <res> <name> k-: remove an annotation
- --overwrite: replace an existing annotation (required for re-runs)
- -l / --all: annotate many objects at once
- No value-format rules, but a 256 KB total payload cap
Example
shell
kubectl annotate deploy/web \
kubernetes.io/change-cause="deploy ${GIT_SHA}" --overwrite
kubectl annotate svc/web prometheus.io/scrape="true" --overwriteIn CI
Set change-cause on each deploy so kubectl rollout history shows which revision was what. Like label, re-running without --overwrite fails. The annotations payload is capped at 256 KB; client-side apply stores last-applied-configuration there, so very large manifests should use --server-side apply.
Key takeaways
- change-cause is the annotation that makes rollout history readable.
- Annotations have no format rules but a 256 KB total cap.
- Add --overwrite for idempotent re-runs, same as label.
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 label: Command Reference for CI/CDReference for kubectl label: add, change, or remove labels, --overwrite for idempotent re-runs, the value-for…
kubectl rollout undo: Command Reference for CI/CDReference for kubectl rollout undo: roll a Deployment back to a previous revision, with rollout history, chan…
kubectl apply: Command Reference for CI/CDReference for kubectl apply: declarative create-or-update from manifests, server-side apply, dry-run validati…