<p>I want to filter pods using set-based selector</p>
<p>given following pods</p>
<pre><code>+ kubectl get pods --show-labels
NAME                                            READY   STATUS    RESTARTS        AGE     LABELS
csi-cephfsplugin-dk7g6                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-cephfsplugin-jlcpv                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-cephfsplugin-ll85n                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-cephfsplugin-pbf5n                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-cephfsplugin-provisioner-6f7ffd894d-9jt8c   6/6     Running   0               7d12h   app=csi-cephfsplugin-provisioner,pod-template-hash=6f7ffd894d
csi-cephfsplugin-provisioner-6f7ffd894d-q74x2   6/6     Running   0               7d12h   app=csi-cephfsplugin-provisioner,pod-template-hash=6f7ffd894d
csi-cephfsplugin-provisioner-6f7ffd894d-vn8m7   6/6     Running   0               7d12h   app=csi-cephfsplugin-provisioner,pod-template-hash=6f7ffd894d
csi-cephfsplugin-sqkz6                          3/3     Running   0               7d12h   app=csi-cephfsplugin,controller-revision-hash=758476fc67,pod-template-generation=12
csi-rbdplugin-2qf4v                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-5f8ng                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-6b9l2                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-6whd8                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-p67v7                             3/3     Running   0               7d12h   app=csi-rbdplugin,controller-revision-hash=79c748c46c,pod-template-generation=12
csi-rbdplugin-provisioner-7dffff7f4d-47bsb      7/7     Running   0               7d12h   app=csi-rbdplugin-provisioner,pod-template-hash=7dffff7f4d
csi-rbdplugin-provisioner-7dffff7f4d-mdzfv      7/7     Running   0               7d12h   app=csi-rbdplugin-provisioner,pod-template-hash=7dffff7f4d
csi-rbdplugin-provisioner-7dffff7f4d-zh76c      7/7     Running   0               7d12h   app=csi-rbdplugin-provisioner,pod-template-hash=7dffff7f4d

&lt; many other pods &gt;

</code></pre>
<p>I want to filter pods with label contain keyword csi,</p>
<pre><code>kubectl get pods -l 'app in (csi)'
</code></pre>
<p>but get error</p>
<pre><code>error: name cannot be provided when a selector is specified
</code></pre>
<p>Any idea ?</p>

qch2012
<p>You can use awk to regex match the pod name.</p>
<pre><code>kubectl get pods --no-headers --show-labels | awk '{if ($NF ~ &quot;.*app=csi.*&quot;) print $0}'
</code></pre>
<p><strong>$NF</strong> is a variable representing the last column in a file/stream.</p>
