You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Need simple kubectl command to see cluster resource usage #17512
Users are getting tripped up by pods not being able to schedule due to resource deficiencies. It can be hard to know when a pod is pending because it just hasn't started up yet, or because the cluster doesn't have room to schedule it. http://kubernetes.io/v1.1/docs/user-guide/compute-resources.html#monitoring-compute-resource-usage helps, but isn't that discoverable (I tend to try a 'get' on a pod in pending first, and only after waiting a while and seeing it 'stuck' in pending, do I use 'describe' to realize it's a scheduling problem).
This is also complicated by system pods being in a namespace that is hidden. Users forget that those pods exist, and 'count against' cluster resources.
There are several possible fixes offhand, I don't know what would be ideal:
Develop a new pod state other than Pending to represent "tried to schedule and failed for lack of resources".
Have kubectl get po or kubectl get po -o=wide display a column to detail why something is pending (perhaps the container.state that is Waiting in this case, or the most recent event.message).
Create a new kubectl command to more easily describe resources. I'm imagining a "kubectl usage" that gives an overview of total cluster CPU and Mem, per node CPU and Mem and each pod/container's usage. Here we would include all pods, including system ones. This might be useful long term alongside more complex schedulers, or when your cluster has enough resources but no single node does (diagnosing the 'no holes large enough' problem).
In this example, the aggregate container requests are 4.455 cores and 20.1 GiB and there are 5 cores and 30GiB total in the cluster.
Reacted by Tuan Anh Tran, Robert Jerzak, Erik Kuefler, Marco Garbelini, Vladimir Rutsky, Wade Holler, Brett Couture, Adam Charnock, Kieren Johnstone, Robson Roberto Souza Peixoto and 214 more
Reacted by EugeneHsu, Pascal Kutscha, Dan Lynch, Roman Pirogov, Filipe Andrade, Ethan Nguyen and Kevin Su
Reacted by danius, Tapani Moilanen, Bradley Wilson-Hunt, Tom Fotherby, Gustavo Medori, Eli Treuherz, Federico Bevione, Dmitri, Aman Singh, Dario Nascimento and 18 more
Reacted by Guy Ellis, Dan Lynch, Roman Pirogov, Saurabh Heda, Filipe Andrade, Ethan Nguyen, cssivision and Felipe Schossler
$ kubectl top nodes
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
cluster1-k8s-master-1 312m 15% 1362Mi 68%
cluster1-k8s-node-1 124m 12% 233Mi 11%
Reacted by Andreas Wederbrand, Yosuke Tomita, Eurico Vidal, Johannes 'fish' Ziemke, Rasmus, Jack Chen, Peter Choi, George Lifchits, Listing Mirror, Tom DeVito and 384 more
Reacted by Nick Irvine, Arthur, Lorenzo Setale, David Dehghan, Yngvar Kristiansen, Roman Naumenko, Karthick Arumugam, CH-ShivikaJindal, Mohamed Shaheen , Denis Biondic and 57 more
Reacted by Duc Mai, Alessandro Bartalucci, Pascal Kutscha, bkalmanj, Hajk, Kevin Su and iometrics-github-integration-masmovil
Reacted by Duc Mai, abhinavagarwal99203, Hajk, prabhukasisekar, Kevin Su, Greg Pelkie, vinh-ngo-webjet, Serhii Vasyliev and eplegaspi
Reacted by Duc Mai, Leah, Maksym Vlasov, breuerjo, Preom Rahman, Isaac Garza, Alex Wellnitz, prabhukasisekar, Kevin Su, iometrics-github-integration-masmovil and 4 more
Reacted by Duc Mai, George Allakhverdyan, abhinavagarwal99203, prabhukasisekar, Kevin Su, iometrics-github-integration-masmovil, Christian Moser, HoseinGhanbari and Serhii Vasyliev
I use below command to get a quick view for the resource usage. It is the simplest way I found.
kubectl describe nodes
Reacted by flyer, hirowatari, Weinan Qiu, Edo Rivai, Leo Gallucci, Günther Grill, spyrosg, Ana, Constantin Bugneac, Adrien Chardon and 229 more
Reacted by Duc Mai, Soroush Kazemi, Hans Fischer, jparadnikas, Navneet Verma, Mark, Emil 'Skeen' Madsen, Carter Fulcher, Harsh Vardhan, Quade Mashaw and 3 more
Reacted by Duc Mai, Soroush Kazemi, pradeep, Valerii Kulyk, Brian Underwood, Emil 'Skeen' Madsen, Carter Fulcher, Quade Mashaw, Kevin Su, robenson-dev and 2 more
Reacted by robotrapta and Zac Li
Reacted by Prayag, Duc Mai, Soroush Kazemi, Andrei Ciobanu, Armel Soro, Hebo Yang, knittl, pradeep, Mark, Emil 'Skeen' Madsen and 7 more
Reacted by Duc Mai, Soroush Kazemi, Guille Vigil, pradeep, Emil 'Skeen' Madsen, Carter Fulcher, Quade Mashaw, Kevin Su, Christian Moser, HoseinGhanbari and 2 more
Reacted by Duc Mai, EugeneHsu, pradeep, Emil 'Skeen' Madsen, Carter Fulcher, Quade Mashaw, Kevin Su, Guilherme Linden and Michael Groenewegen van der Weijden
If there was a way to "format" the output of kubectl describe nodes, I wouldn't mind scripting my way to summarize all node's resource requests/limits.
here is my hack kubectl describe nodes | grep -A 2 -e "^\\s*CPU Requests"
Reacted by Bill Wang, Thilina Piyasundara, Martin Lazarov, Eurico Vidal, siner, Shah Newaz Khan, S.A, Kaleo, Miguel Almeida, Pedro Spagiari and 121 more
Reacted by André Menezes, Seth Miller and Sascha Hannes
Reacted by Naomi Lin, Panna, Olivier Chatry, Pat Heard, Jan Posvic, Valentín Palacios, Marco Suter, Constantin Bugneac, Mohammad-Mohsen Aseman-Manzar, Moritz Gunz and 1 more
$ cat bin/node-resources.sh
#!/bin/bash
set -euo pipefail
echo -e "Iterating...\n"
nodes=$(kubectl get node --no-headers -o custom-columns=NAME:.metadata.name)
for node in $nodes; do
echo "Node: $node"
kubectl describe node "$node" | sed '1,/Non-terminated Pods/d'
echo
done
Reacted by Adam Charnock, Christiaan Hees, Eric Sniff, Christian Flack, Julian V. Modesto, renuraj18, Matt Brown, Javier Moreno, George Paoli, Kingdon Barrett and 44 more
@goltermann There are no sig labels on this issue. Please add a sig label by: (1) mentioning a sig: @kubernetes/sig-<team-name>-misc (2) specifying the label manually: /sig <label>
Note: method (1) will trigger a notification to the team. You can find the team list here.
From the long history of comments here it seems everyone has different expectations by the many issues and requests reported in this thread. This thread is more of a wiki now.
We'd be happy to see one of these plugins be proposed for upstreaming via a KEP. If someone wants to own this and bias for action with a decision, please open a KEP for discussion.
/close
Reacted by Lennart Jern, Keith Layne and Oren Mazor
Reacted by Kevin N., Quinn Bast, ryan4yin | 二花, Adonis and Karol Baraniecki
From the long history of comments here it seems everyone has different expectations by the many issues and requests reported in this thread. This thread is more of a wiki now.
We'd be happy to see one of these plugins be proposed for upstreaming via a KEP. If someone wants to own this and bias for action with a decision, please open a KEP for discussion.
/close
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
In case folks are still listening in on this issue...Has anyone attempted using the standard resource usage apis like getrusage() for sw running inside containers/pods(). For cpu stats it does not seem that it will far off from what the node level cgroup would have to report.
mem stats seem more problematic. Unclear whether say /sys/fs/crgoup/memory/<> from inside a container really reflects memory usage correctly. Being able to monitor the resource usage from within an app (and then changing behavior in the app etc.) is a neat capability. Seems unclear when that will be available in k8s so casting around for workarounds.
Reacted by Zappone Federico, Dr. Halil-Cem Gürsoy, jmrnilsson, dguyhasnoname, Chris McConnell, Daniel Pawlik, Genzer Hawker, danlhennessy, Luke Pendleton, Stanislav Hrechykhin and 5 more
Getting in on this shell scripting party. I have an older cluster running the CA with scale down disabled. I wrote this script to determine roughly how much I can scale down the cluster when it starts to bump up on its AWS route limits:
Update of @julienlau's code, modified it a bit to show usage, added 2 flags (--nodes <node1> <node2> <node3> to print data from specific nodes only, and --pool <pool name> for specific pool - those 2 flags are exclusive) and made indention dynamic, based on nodes' names. Tested with bash 5.2, zsh 5.9, kubectl 1.27
Unfortunately KubeNodeUsage is pretty but does not output all information in one command.
The bare minimum is to be able to get these 3 metrics :
memory usage (real), memory request, memory limits
This is what does kube-capacity --util
Activity
davidopp commentedon Nov 20, 2015
Something along the lines of (2) seems reasonable, though the UX folks would know better than me.
(3) seems vaguely related to #15743 but I'm not sure they're close enough to combine.
chrishiestand commentedon Sep 15, 2016
In addition to the case above, it would be nice to see what resource utilization we're getting.
kubectl utilization requestsmight show (maybekubectl utilorkubectl usageare better/shorter):In this example, the aggregate container requests are 4.455 cores and 20.1 GiB and there are 5 cores and 30GiB total in the cluster.
xmik commentedon Dec 19, 2016
There is:
ozbillwang commentedon Jan 11, 2017
I use below command to get a quick view for the resource usage. It is the simplest way I found.
tonglil commentedon Jan 20, 2017
If there was a way to "format" the output of
kubectl describe nodes, I wouldn't mind scripting my way to summarize all node's resource requests/limits.from-nibly commentedon Feb 1, 2017
here is my hack
kubectl describe nodes | grep -A 2 -e "^\\s*CPU Requests"jesseredl commentedon May 25, 2017
@from-nibly thanks, just what i was looking for
tonglil commentedon May 25, 2017
Yup, this is mine:
k8s-github-robot commentedon May 31, 2017
@goltermann There are no sig labels on this issue. Please add a sig label by:
(1) mentioning a sig:
@kubernetes/sig-<team-name>-misc(2) specifying the label manually:
/sig <label>Note: method (1) will trigger a notification to the team. You can find the team list here.
0xmichalis commentedon Jun 10, 2017
@kubernetes/sig-cli-misc
94 remaining items
eddiezane commentedon Mar 31, 2021
From the long history of comments here it seems everyone has different expectations by the many issues and requests reported in this thread. This thread is more of a wiki now.
We'd be happy to see one of these plugins be proposed for upstreaming via a KEP. If someone wants to own this and bias for action with a decision, please open a KEP for discussion.
/close
k8s-ci-robot commentedon Mar 31, 2021
@eddiezane: Closing this issue.
Details
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
champak commentedon Apr 15, 2021
In case folks are still listening in on this issue...Has anyone attempted using the standard resource usage apis like getrusage() for sw running inside containers/pods(). For cpu stats it does not seem that it will far off from what the node level cgroup would have to report.
mem stats seem more problematic. Unclear whether say /sys/fs/crgoup/memory/<> from inside a container really reflects memory usage correctly. Being able to monitor the resource usage from within an app (and then changing behavior in the app etc.) is a neat capability. Seems unclear when that will be available in k8s so casting around for workarounds.
dguyhasnoname commentedon Jun 18, 2021
another tool to see resources node-wise, namespace-wise: https://github.com/dguyhasnoname/k8s-day2-ops/tree/master/resource_calcuation/k8s-toppur
jackdpeterson commentedon Sep 21, 2021
My hack (on k8s 1.18; EKS)
shawncao commentedon Nov 7, 2021
Lots of gems in this thread, :) thanks all! (wish some good writer could summarize and publish a quick sheet for it)
valxv commentedon Nov 10, 2021
@jackdpeterson answer adapted for Powershell :)
kubectl describe nodes | Select-String -Pattern 'Allocated resources:' -Context 0,5sanderdescamps commentedon Nov 19, 2021
Without counting the lines
kubectl describe nodes | awk '/Allocated resources/,/Events/' | grep -v "^Events:"solidsnack commentedon Jul 6, 2022
It's not perfect, but we can get a serviceable summary with
sed:panpan0000 commentedon Sep 18, 2022
Below script only works in the
kubectl describe nodevalues are in unit "m/Ki".julienlau commentedon Nov 23, 2022
Updated version of this shell function
d-mankowski-synerise commentedon Sep 23, 2023
Update of @julienlau's code, modified it a bit to show usage, added 2 flags (
--nodes <node1> <node2> <node3>to print data from specific nodes only, and--pool <pool name>for specific pool - those 2 flags are exclusive) and made indention dynamic, based on nodes' names. Tested with bash 5.2, zsh 5.9, kubectl 1.27as an alternative - kube-capcity seems to do the job
AKSarav commentedon Mar 28, 2025
Try KubeNodeUsage
https://github.com/AKSarav/KubeNodeUsage
julienlau commentedon Mar 31, 2025
Unfortunately KubeNodeUsage is pretty but does not output all information in one command.
The bare minimum is to be able to get these 3 metrics :
memory usage (real), memory request, memory limits
This is what does
kube-capacity --util