Skip to content

Instantly share code, notes, and snippets.

@george-angel
Last active February 8, 2018 16:40
Show Gist options
  • Save george-angel/c95b21262934da53df6481f6264866bc to your computer and use it in GitHub Desktop.
Save george-angel/c95b21262934da53df6481f6264866bc to your computer and use it in GitHub Desktop.
Kubernetes resources per namespace
#!/bin/bash
## usage: ./rs-ns <kube-context> | sort -h -k 2 -r
export env=${1}
total() {
ns=${1}
echo "${ns} $(kubectl --context=${env} -n${ns} top pod | tail -n +2 | awk '{print $3}' | cut -d'M' -f1 | paste -s -d+ - | bc) "
}
export -f total
kubectl --context=${env} get ns | tail -n +2 | awk '{print $1}' | xargs -I {} -n1 sh -c 'total {}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment