Skip to content

Instantly share code, notes, and snippets.

@3ng1n33r
Created March 15, 2026 11:57
Show Gist options
  • Select an option

  • Save 3ng1n33r/a66448e0c4feffb0da108b73c5d623b5 to your computer and use it in GitHub Desktop.

Select an option

Save 3ng1n33r/a66448e0c4feffb0da108b73c5d623b5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
DATA_DIR="/opt/local-path-provisioner"
PV_LIST=$(kubectl get pv -o json | jq -r '.items[] | select(.spec.hostPath.path != null) | .spec.hostPath.path')
#for node in $(kubectl get nodes -o name | cut -d/ -f2); do
for node in $(kubectl get nodes -o wide | awk '{print $6}' | tail -n +2); do
echo
echo "===== NODE: $node ====="
ssh -o "StrictHostKeyChecking=no" "pi@$node" "ls -1 $DATA_DIR" 2>/dev/null | while read dir; do
fullpath="$DATA_DIR/$dir"
if ! grep -q "$fullpath" <<< "$PV_LIST"; then
size=$(ssh -o "StrictHostKeyChecking=no" -n "pi@$node" "du -sh '$fullpath' 2>/dev/null | cut -f1")
echo "[ORPHAN] $node:$fullpath size=$size"
#echo "[ORPHAN] $node:$fullpath"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment