Determine disk usage by PVC


#1

Save and run this script as root to determine how much storage each PVC is consuming.

#!/bin/bash

cd /var/lib/kubelet/pods

while read -r line; do
        relpath=$(echo $line | awk '{ print $2 }')
        pv=$(basename $relpath)
        pvc=$(KUBECONFIG=/etc/kubernetes/admin.conf kubectl get pv $pv --all-namespaces --no-headers | awk '{ print $6 }')
        size=$(echo $line | awk '{ print $1 }')

        echo "$size     $pvc"
done < <(find . -type d -name 'pvc-*' | xargs du -sh | sort -hr)