Skip to content

Instantly share code, notes, and snippets.

@petskratt
Created July 18, 2023 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petskratt/f4009f2bf1a1ebcbb96196cae5ed3be5 to your computer and use it in GitHub Desktop.
Save petskratt/f4009f2bf1a1ebcbb96196cae5ed3be5 to your computer and use it in GitHub Desktop.
# Display current K8S resource usage for a namespace (either first argument or current)
# Add to your ~/.profile, copy-paste results for analysis to https://docs.google.com/spreadsheets/d/1v___k9gYo4RI4wWIluJcdqOVHCFEccLQMOCGxvrZGtk/edit?usp=sharing
# peeter.marvet@vaimo.com / 2023-07-18
function resource_capacity() {
if [ -z "$1" ]
then
namespace=$(kubectl config view --minify -o jsonpath='{..namespace}')
else
namespace="$1"
fi
kubectl resource-capacity --util --pods -n $namespace | tr -s '[:blank:]' "\t" | sed -r 's/([[:digit:]]+)Mi\t/\1\t/g' | sed -r 's/([[:digit:]]+)m\t/\1\t/g' | sed -r 's/^(gke-k[[:digit:]]+)-gcp-/\1\t/g' | grep -v "*" | sed '/^\t$/d' | grep -v "POD\tCPU\tREQUESTS" | sed -r 's/\([[:digit:]]+%\)(\t|$)//g' | cut -f3-
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment