<p>I am using the python kubernetes api with <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#list_namespaced_pod" rel="noreferrer">list_namespaced_pod</a> to get the pods in my namespace. Now I would like to filter them, using the optional label selector parameter. </p>

<p>The <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/CoreV1Api.md#list_namespaced_pod" rel="noreferrer">documention</a> describes this parameter as </p>

<blockquote>
  <p>A selector to restrict the list of returned objects by their labels.
  Defaults to everything.</p>
</blockquote>

<p>It does not bother to give an example. On <a href="https://www.programcreek.com/python/example/96328/kubernetes.client.CoreV1Api" rel="noreferrer">this website</a>, I found several possibilities on how to use the attribute. I already tried </p>

<pre><code>label_selector='label=my_label'
label_selector='label:my_label'
label_selector='my_label'
</code></pre>

<p>non of which is working. How do I use the parameter label_selector correctly?</p>

<p>Kubernetes CLI uses two types of label selectors.</p>

<ol>
<li><p>Equality Based
Eg: <code>kubectl get pods  -l key=value</code></p></li>
<li><p>Set Based
Eg: <code>kubectl get pod -l 'key in (value1,value2)'</code></p></li>
</ol>

<p><code>label_selector='label=my_label'</code> </p>

<p>should work, else try using </p>

<p><code>label_selector='label in (my_label1, my_label2)'</code>.</p>

<p>If this does not work the error might come from somewhere else.</p>
