<p>i would like to list all pods of a specific namespace but only those that are controlled by deployment
i have tried this but didn't succeed:
<code>kubectl get pods --all-namespaces -o json | jq -r '.items | map(select(.metadata.ownerReferences == deployment ) | .metadata.name) | .[]'</code></p>
<p>I use this command:
<code>kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.namespace}{&quot;\t&quot;}{.spec.containers[*].name}{&quot;\n&quot;}{end}' --all-namespaces |sed 's/\t/\'$'\\/g' | sort | uniq</code>
to list all containers and their namespaces so i want the same but filtering out all non-deployments kind</p>

<p>You can use the <code>--custom-columns</code> to find out which pods are controlled, and which kind of controller is the owner. Example:</p>
<pre><code>$ kubectl get pods --all-namespaces -o custom-columns=NAME:.metadata.name,CONTROLLER:.metadata.ownerReferences[].kind,NAMESPACE:.metadata.namespace
NAME                                        CONTROLLER   NAMESPACE
nginx-858dbf7665-8t9vv                      ReplicaSet   default
coredns-74ff55c5b-xpgnq                     ReplicaSet   kube-system
etcd-minikube                               Node         kube-system
ingress-nginx-admission-create-n6j7k        Job          kube-system
ingress-nginx-admission-patch-45xvw         Job          kube-system
ingress-nginx-controller-65cf89dc4f-g7lwm   ReplicaSet   kube-system
kindnet-44pq8                               DaemonSet    kube-system
kindnet-nqhg9                               DaemonSet    kube-system
kube-apiserver-minikube                     Node         kube-system
kube-controller-manager-minikube            Node         kube-system
kube-proxy-nmzbn                            DaemonSet    kube-system
kube-proxy-wlmdz                            DaemonSet    kube-system
kube-scheduler-minikube                     Node         kube-system
metrics-server-58966dd6b9-schjr             ReplicaSet   kube-system
storage-provisioner                         &lt;none&gt;       kube-system
</code></pre>
<hr />
<p>Remember that <em>Deployments</em> automatically creates <em>ReplicaSets</em> and rely on them to manage a set of pods and its desired state/replicas. So you can just filter them:</p>
<pre><code>$ kubectl get pods --all-namespaces -o json | jq -r '.items | map(select(.metadata.ownerReferences[]?.kind == &quot;ReplicaSet&quot; ) | .metadata.name) | .[]'
nginx-858dbf7665-8t9vv
coredns-74ff55c5b-xpgnq
ingress-nginx-controller-65cf89dc4f-g7lwm
metrics-server-58966dd6b9-schjr
</code></pre>
