67

I have a Kubernetes cluster on Google Cloud Platform. It has a persistent Volume Claim with a Capacity of 1GB. The persistent volume claim is bound to many deployments.

I would like to identify the space left in the persistent Volume Claim in order to know if 1GB is sufficient for my application.

I have used the command "kubectl get pv" but this does not show the storage space left.

Jonas
  • 121,568
  • 97
  • 310
  • 388
ilegolas
  • 805
  • 1
  • 7
  • 10

5 Answers5

78

If there's a running pod with mounted PV from the PVC,

kubectl -n <namespace> exec <pod-name> -- df -ah

...will list all file systems, including the mounted volumes, and their free disk space.

Benbob
  • 13,876
  • 18
  • 79
  • 114
apisim
  • 4,036
  • 1
  • 10
  • 16
28

You can monitorize them with kubelet prometheus metrics:

kubelet_volume_stats_available_bytes{persistentvolumeclaim="your-pvc"}
kubelet_volume_stats_capacity_bytes{persistentvolumeclaim="your-pvc"}
adiga
  • 34,372
  • 9
  • 61
  • 83
Chus
  • 926
  • 8
  • 9
  • unfortunately doesn't work with GP3 volumes as of today :/ see https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues/816 – Tom Sep 10 '21 at 15:10
  • 2
    'kubelet_volume_stats_used_bytes' see https://stackoverflow.com/a/47117776/1747983 – Tilo Oct 21 '21 at 22:07
15

I wrote a script that lists all the PVCs in a cluster in a format similar to df.

You can run it via:

./kubedf

or:

./kubedf -h

for a human readable output.

Edit: The script no longer requires kubectl proxy to be running

Brendan McGrath
  • 278
  • 2
  • 5
9

Adding to @apisim's answer if you add -h parameter then you can get details in human readable format. Something like this,

kubectl -n <namespace> exec <pod-name> -- df -h

enter image description here

nandeesh
  • 753
  • 7
  • 16
0

If you are using NFS:

sudo apt update
sudo apt install ncdu
cd /your_nfs/kubernetes/
sudo ncdu .
ncdu 1.12 ~ Use the arrow keys to navigate, press ? for help
--- /your_nfs/kubernetes/ ----------------------------------------------------------------------------------
   34.1 GiB [##########] /backups
    2.1 GiB [          ] /redis
    1.9 GiB [          ] /XXX
  785.5 MiB [          ] /postgresql
  435.7 MiB [          ] /XXX
  391.2 MiB [          ] /XXX

Press C to see number/count of files.

qräbnö
  • 2,722
  • 27
  • 40