Kubernetes CKA sample exam question 101 with answer

Question
List all the pods running in ALL namespaces based on CPU utilization. Save the output to /tmp/pod-high-cpu.txt.
Deploy the metrics server first if you already don’t have one.

Answer
You can list Pods and Nodes using kubectl top command similar to Linux top command. However you need to deploy metrics server first which you can get from this link.
Also, switches --all-namespace and -A refer to all namespaces:

kubectl top pods -A --sort-by=cpu > /tmp/pod-high-cpu.txt
or:
kubectl top pods --all-namespaces --sort-by=cpu > /tmp/pod-high-cpu.txt