Skip to content

Instantly share code, notes, and snippets.

@charlieegan3
Created November 10, 2020 15:59
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 charlieegan3/e1dccfa571665b3dded577d80fc29c9f to your computer and use it in GitHub Desktop.
Save charlieegan3/e1dccfa571665b3dded577d80fc29c9f to your computer and use it in GitHub Desktop.
Script to download data about the volume of resources in a cluster
#!/usr/bin/env bash
set -eo pipefail
OUTPUT_DIR=output
mkdir -p $OUTPUT_DIR
resources=($(kubectl api-resources | tail -n +2 | awk '{ print $1 }'))
ignore=("bindings" "tokenreviews" "localsubjectaccessreviews" "selfsubjectaccessreviews" "selfsubjectrulesreviews" "subjectaccessreviews")
for i in "${resources[@]}"
do
:
if [[ ! " ${ignore[@]} " =~ " ${i} " ]]; then
>&2 echo getting $i
kubectl get "$i" --all-namespaces -o json > "$OUTPUT_DIR/$i.json"
fi
done
for f in `find $OUTPUT_DIR -type f`
do
echo $(cat $f | jq '.items | length') $(basename $f)
done
du -sh $OUTPUT_DIR/* | sort -h
rm -r $OUTPUT_DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment