Managing Annotations

1. Adding Annotations

CommandAction
kubectl annotate pod web owner=alice@x.comAdd annotation
kubectl annotate deploy web kubernetes.io/change-cause="v1.4.2"Track rollout cause
kubectl annotate pod web key=val --overwriteUpdate

2. Viewing Annotations

kubectl get pod web -o jsonpath='{.metadata.annotations}'
kubectl describe pod web | grep -A1 Annotations
ToolUse
describeHuman-readable
jsonpathScript/extract
yq '.metadata.annotations'Manipulate YAML

3. Removing Annotations

kubectl annotate pod web owner-
SyntaxEffect
key-Remove annotation

4. Using Annotations in YAML

metadata:
  annotations:
    description: "Public web frontend"
    deploy.timestamp: "2026-05-21T10:00Z"
    contact: "team-web@example.com"
Difference vs LabelsAnnotation
SelectableNo
SizeUp to 256 KiB total per object
ContentArbitrary strings, JSON, binary (b64)

5. Understanding Common Annotations

AnnotationUse
kubectl.kubernetes.io/last-applied-configurationSet by kubectl apply
kubernetes.io/change-causeDescription in rollout history
deployment.kubernetes.io/revisionAuto-incremented revision
scheduler.alpha.kubernetes.io/...Scheduler-specific hints

6. Using Deployment Annotations

AnnotationEffect
kubernetes.io/change-causeRecorded per revision
deployment.kubernetes.io/revision-history-limitEquivalent of spec field
field.cattle.io/...Rancher-specific

7. Configuring Ingress Annotations

ControllerCommon Annotation
NGINXnginx.ingress.kubernetes.io/rewrite-target: /$1
NGINXnginx.ingress.kubernetes.io/proxy-body-size: 50m
ALB (AWS)alb.ingress.kubernetes.io/scheme: internet-facing
cert-managercert-manager.io/cluster-issuer: letsencrypt
Traefiktraefik.ingress.kubernetes.io/router.middlewares: ns-redirect@kubernetescrd

8. Using Prometheus Annotations

metadata:
  annotations:
    prometheus.io/scrape: "true"
    prometheus.io/port: "9090"
    prometheus.io/path: "/metrics"
    prometheus.io/scheme: "http"
AnnotationEffect
prometheus.io/scrapeEnable scraping
prometheus.io/portMetrics port
prometheus.io/pathMetrics path

9. Setting Autoscaler Annotations

AnnotationEffect
cluster-autoscaler.kubernetes.io/safe-to-evict: "true"Allow CA to evict pod
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"Pin pod to node
karpenter.sh/do-not-disrupt: "true"Karpenter equivalent

10. Understanding Annotation Size Limits

LimitValue
Total per object256 KiB (all annotations combined)
KeySame as labels (≤253 prefix + ≤63 name)
ValueNo per-key limit (subject to total)
Warning: etcd performance suffers with large objects; keep annotations small.