<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>Please use below command:</p>
<pre><code>kubectl get pods --all-namespaces -o json | jq '.items | group_by(.metadata.namespace) | map({&quot;namespace&quot;: .[0].metadata.namespace, &quot;NoOfPods&quot;: (length)})'
</code></pre>
<p>Output format:</p>
<pre><code>[
  {
    &quot;namespace&quot;: &quot;keda&quot;,
    &quot;NoOfPods&quot;: 3
  },

  {
    &quot;namespace&quot;: &quot;kube-system&quot;,
    &quot;NoOfPods&quot;: 12
  },

  {
    &quot;namespace&quot;: &quot;prod&quot;,
    &quot;NoOfPods&quot;: 1
  },

  {
    &quot;namespace&quot;: &quot;stage&quot;,
    &quot;NoOfPods&quot;: 1
  }

]
</code></pre>
