How can I get pods by label, using the python kubernetes api?
this works for me:
v1.list_namespaced_pod(namespace='default', label_selector='job_name={}'.format(name))
Kubernetes CLI uses two types of label selectors.
Equality BasedEg:
kubectl get pods -l key=value
Set BasedEg:
kubectl get pod -l 'key in (value1,value2)'
label_selector='label=my_label'
should work, else try using
label_selector='label in (my_label1, my_label2)'
.
If this does not work the error might come from somewhere else.
(Python client) This works for me and it returns JSON
result = v1.list_namespaced_pod( "default", label_selector="label_key=label_value",watch=False)print(len(result.items))