Last active
May 16, 2025 16:14
-
-
Save nyrahul/7ff0b9742bb44e105480491eb73cae94 to your computer and use it in GitHub Desktop.
Sum up CPU/Memory Limits/Requests for a given k8s namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
js=$(kubectl get pods -n agents -o json) && \ | |
cpur=$(echo $js | jq '.items[].spec.containers[]?.resources.requests.cpu' | sed -r 's/([0-9]*)m/\1/' | sed -e 's/"//g' -e 's/,//g' | paste -sd+ - | bc) && \ | |
cpul=$(echo $js | jq '.items[].spec.containers[]?.resources.limits.cpu' | sed -r 's/([0-9]*)m/\1/' | sed -e 's/"//g' -e 's/,//g' | paste -sd+ - | bc) && \ | |
memr=$(echo $js | jq '.items[].spec.containers[]?.resources.requests.memory' | sed -r 's/([0-9]*)Mi/\1/' | sed -e 's/"//g' -e 's/,//g' | paste -sd+ - | bc) && \ | |
meml=$(echo $js | jq '.items[].spec.containers[]?.resources.limits.memory' | sed -r 's/([0-9]*)Mi/\1/' | sed -e 's/"//g' -e 's/,//g' | paste -sd+ - | bc) && \ | |
echo -en "CPU Requests=${cpur}m, CPU Limits=${cpul}m\nMem Requests=${memr}Mi, Mem Limits=${meml}Mi\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample Output: