How to find Pods by label

This section explains how to find Kubernetes pods by a set of known labels.

Calling objects on the Pod class returns a Query object which provides the filter method. The selector parameter can take a dictionary of label names and values to filter by:

for pod in Pod.objects(api).filter(namespace=pykube.all, selector={'app': 'myapp'}):

Note that the special value of pykube.all needs to be passed, otherwise it would only return pods in the current namespace (i.e. usually “default”).