Skip to content

Find Kubernetes Pods by Annotation Using kubectl

kubernetes, kubectl, jq1 min read

Sometimes you may need to retrieve pods with kubectl using an attribute that isn't available as a label or filter, such as an annotation. You can due this by getting all pods and filtering using jq.

1kubectl get pods --chunk-size=0 -o json | \
2 jq -r '.items[] | select(.metadata.annotations.myAnnotation == "myValue") |'

Now you have a list of all of the pod names that have myValue for myAnnotation.

Note that if you have thousands and thousands of pods, this isn't going to be the fastest thing in the world, but it is still going to work.