Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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