Skip to main content
duffn.dev

Find Kubernetes Pods by Annotation Using kubectl

Share: 

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.

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

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.