<p>I have a list of namespaces created under the same k8s cluster and I'd like to find out the resource (CPU, memory) usage per namespace. Is there any command I can use?</p>

injoy
<p>Yes. You can use</p>

<pre><code>$ kubectl -n &lt;nampespace&gt; top pod
</code></pre>

<p>For example:</p>

<pre><code>$ kubectl top pod -n kube-system
NAME                                                                 CPU(cores)   MEMORY(bytes)
calico-node-xxxxx                                                    17m          166Mi
coredns-xxxxxxxxxx-xxxxx                                             2m           11Mi
coredns-xxxxxxxxxx-xxxxx                                             3m           11Mi
etcd-ip-x-x-x-x.us-west-2.compute.internal                           19m          149Mi
kube-apiserver-ip-x-x-x-x.us-west-2.compute.internal                 39m          754Mi
kube-controller-manager-ip-x-x-x-x.us-west-2.compute.internal        20m          138Mi
kube-proxy-xxxxx                                                     5m           12Mi
kube-scheduler-ip-x-x-x-x.us-west-2.compute.internal                 6m           17Mi
metrics-server-xxxxxxxxxx-xxxxx                                      0m           15Mi
</code></pre>

<p>You need to add up all the entries on the CPU and MEMORY columns if you want the total.</p>

<p>Note that for <code>kubectl top</code> to work you need to have the <a href="https://github.com/kubernetes-incubator/metrics-server" rel="noreferrer">metrics-server</a> set up and configured appropriately. (Older clusters use the <a href="https://github.com/kubernetes-retired/heapster" rel="noreferrer">heapster</a>)</p>
