annotation

Annotating Kubernetes Resources

Update the annotations on one or more resources

All Kubernetes objects support the ability to store additional data with the object as annotations. Annotations are key/value pairs that can be larger than labels and include arbitrary string values such as structured JSON. Tools and system extensions may use annotations to store their own data.

Command

  1. $ kubectl annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]

Example

Current State

  1. $ kubectl get pods
  2. NAME READY STATUS RESTARTS AGE
  3. nginx-6db489d4b7-zcc8h 1/1 Running 0 5s

Command

  1. $ kubectl annotate pods nginx-6db489d4b7-zcc8h description='standard gateway'
  2. pod/nginx-6db489d4b7-zcc8h annotated

More Examples

  1. # Update pod 'foo' with the annotation 'description' and the value 'my frontend'.
  2. # If the same annotation is set multiple times, only the last value will be applied
  3. kubectl annotate pods foo description='my frontend'
  1. # Update a pod identified by type and name in "pod.json"
  2. kubectl annotate -f pod.json description='my frontend'
  1. # Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx', overwriting any
  2. existing value.
  3. kubectl annotate --overwrite pods foo description='my frontend running nginx'
  1. # Update all pods in the namespace
  2. kubectl annotate pods --all description='my frontend running nginx'
  1. # Update pod 'foo' only if the resource is unchanged from version 1.
  2. kubectl annotate pods foo description='my frontend running nginx' --resource-version=1
  1. # Update pod 'foo' by removing an annotation named 'description' if it exists.
  2. # Does not require the --overwrite flag.
  3. kubectl annotate pods foo description-