Skip to content

Instantly share code, notes, and snippets.

@petskratt
Created July 18, 2023 12:16
Show Gist options
  • Save petskratt/f4009f2bf1a1ebcbb96196cae5ed3be5 to your computer and use it in GitHub Desktop.
Save petskratt/f4009f2bf1a1ebcbb96196cae5ed3be5 to your computer and use it in GitHub Desktop.

Revisions

  1. petskratt created this gist Jul 18, 2023.
    16 changes: 16 additions & 0 deletions resource_capacity.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # 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
    # [email protected] / 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-

    }