Question
After a new deployment, some pods are “Pending” and cannot be scheduled by Kubernetes on any node, due to resources shortage.
How do I find out which pods are requesting a lot of CPU?
Answer
You can easily see the minimum requested CPU for each pod with this command:
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[].resources.requests.cpu}{"\n"}{end}'
If you want to see the CPU limits for each pod in the cluster the command is similar:
kubectl get pods --all-namespaces -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[].resources.limits.cpu}{"\n"}{end}'
The above commands show the minimum CPU guaranteed and the maximum CPU allowed. They show your configuration, not the actual / current usage of the pods. If you want to see the current CPU usage for each pod you can use this command:
kubectl top pods
Finally if you want better data visualization and charts for CPU usage, requests and limits (for pods and for nodes) you can use Prometheus and K8s Lens for example.