<p>Im looking to get the number of pods on a cluster by namespace. Is this possible with a kubectl command?</p>
<p>Looking to exclude certain namespaces as well</p>
<p>kubectl get pods gets me a list of every pod.</p>

<p>I have just modified the command posted in the above answer owing to OP's need of excluding certain namespaces as well.</p>
<pre><code>kubectl get pods --all-namespaces -o json | jq '[.items[] | select(.metadata.namespace != &quot;logging&quot;)] | group_by(.metadata.namespace) | map({&quot;namespace&quot;: .[0].metadata.namespace, &quot;NoOfPods&quot;: (length)})'
</code></pre>
<p>Result without exclusion:</p>
<p><a href="https://i.stack.imgur.com/QJ5iv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QJ5iv.png" alt="enter image description here" /></a></p>
<p>Result after exclusion:</p>
<p><a href="https://i.stack.imgur.com/YBydy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YBydy.png" alt="enter image description here" /></a></p>
<p>In here, I'm excluding the pods from <code>logging</code> namespace only but you can exclude more namespaces using the format:</p>
<pre><code>.metadata.namespace != &quot;logging&quot; and .metadata.namespace != &quot;monitoring&quot;
</code></pre>
<p>Hope this helps!</p>
