Pvcs show total mounts

From UVOO Tech Wiki
Jump to navigation Jump to search
#!/bin/bash

echo "Mounted PVCs (namespace/pvc -> pod on node):"
echo

kubectl get pods --all-namespaces -o json | jq -r '
  .items[] |
  . as $pod |
  .spec.volumes[]? |
  select(.persistentVolumeClaim != null) |
  "\($pod.metadata.namespace)\t\(.persistentVolumeClaim.claimName)\t\($pod.metadata.name)\t\($pod.spec.nodeName)"
' | sort | uniq | column -t -s $'\t'

echo
echo "Total actively mounted PVCs: $(kubectl get pods --all-namespaces -o json | jq '[.items[].spec.volumes[]? | select(.persistentVolumeClaim != null)] | length')"