<p>I have namespace with few deployments. One of the deployments has a specific label (<code>my-label=yes</code>). I want to get all the pods with this label.</p>
<p>This is how it done with <code>kubectl</code>:</p>
<pre><code>kdev get pods -l my-label=yes
</code></pre>
<p>it's working.</p>
<p>Now I want to do it with Kubernetes API. This is the closest point I get:</p>
<pre><code>curl https://kubernetes.default.svc/api/v1/namespaces/XXX/pods --silent --header &quot;Authorization: Bearer $TOKEN&quot; --insecure
</code></pre>
<p>This command get all the pods in the namespace. I want to filter the results to all the pods with this requested label. How to do it?</p>
<p>Even more wide question: Is this possible to &quot;translate&quot; kubectl command into REST API call?</p>

No1Lives4Ever
<blockquote>
<p>Is this possible to &quot;translate&quot; kubectl command into REST API call?</p>
</blockquote>
<p>When you execute any command using kubectl it internally gets translated into a REST call with json payload before sending it to Kubernetes API Server. An easy way to inspect that is to run the command with verbosity increased</p>
<pre><code>kubectl get pods -n kube-system -l=tier=control-plane --v=8
I0730 15:21:01.907211    5320 loader.go:375] Config loaded from file:  /Users/arghyasadhu/.kube/config
I0730 15:21:01.912119    5320 round_trippers.go:420] GET https://xx.xx.xxx.xxx:6443/api/v1/namespaces/kube-system/pods?labelSelector=tier%3Dcontrol-plane&amp;limit=500
I0730 15:21:01.912135    5320 round_trippers.go:427] Request Headers:
I0730 15:21:01.912139    5320 round_trippers.go:431]     Accept: application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1beta1;g=meta.k8s.io,application/json
I0730 15:21:01.912143    5320 round_trippers.go:431]     User-Agent: kubectl/v1.18.0 (darwin/amd64) kubernetes/9e99141
I0730 15:21:02.071778    5320 round_trippers.go:446] Response Status: 200 OK in 159 milliseconds
I0730 15:21:02.071842    5320 round_trippers.go:449] Response Headers:
I0730 15:21:02.071858    5320 round_trippers.go:452]     Cache-Control: no-cache, private
I0730 15:21:02.071865    5320 round_trippers.go:452]     Content-Type: application/json
I0730 15:21:02.071870    5320 round_trippers.go:452]     Date: Thu, 30 Jul 2020 09:51:02 GMT
I0730 15:21:02.114281    5320 request.go:1068] Response Body: {&quot;kind&quot;:&quot;Table&quot;,&quot;apiVersion&quot;:&quot;meta.k8s.io/v1&quot;,&quot;metadata&quot;:{&quot;selfLink&quot;:&quot;/api/v1/namespaces/kube-system/pods&quot;,&quot;resourceVersion&quot;:&quot;1150005&quot;},&quot;columnDefinitions&quot;:[{&quot;name&quot;:&quot;Name&quot;,&quot;type&quot;:&quot;string&quot;,&quot;format&quot;:&quot;name&quot;,&quot;description&quot;:&quot;Name must be unique within a namespace. Is required when creating resources, although some resources may allow a client to request the generation of an appropriate name automatically. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names&quot;,&quot;priority&quot;:0},{&quot;name&quot;:&quot;Ready&quot;,&quot;type&quot;:&quot;string&quot;,&quot;format&quot;:&quot;&quot;,&quot;description&quot;:&quot;The aggregate readiness state of this pod for accepting traffic.&quot;,&quot;priority&quot;:0},{&quot;name&quot;:&quot;Status&quot;,&quot;type&quot;:&quot;string&quot;,&quot;format&quot;:&quot;&quot;,&quot;description&quot;:&quot;The aggregate status of the containers in this pod.&quot;,&quot;priority&quot;:0},{&quot;name&quot;:&quot;Restarts&quot;,&quot;type&quot;:&quot;integer&quot;,&quot;format&quot;:&quot;&quot;,&quot;description&quot;:&quot;The number of times the containers in this pod have been restarted.&quot;,&quot;priority&quot;:0},{&quot;name&quot;:&quot;Age&quot;,&quot;type&quot;:&quot;strin [truncated 16503 chars]
</code></pre>
