Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify the storage space left in a persistent volume claim?

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.

like image 636
ilegolas Avatar asked Nov 08 '18 02:11

ilegolas


People also ask

What is storage class in persistent volume?

A storageclass is a Kubernetes object that stores information about creating a persistent volume for your pod. With a storageclass, you do not need to create a persistent volume separately before claiming it.

How do I view files in persistent volume?

First, find out your pvc's mountPath. Your data sits there. Second, you can access it from the pod that uses the PersistentVolumeClaim. Fire up a terminal on the pod and use your favourite tools like ls and df to list files or see stats of the volume usage.

How does a persistent volume claim work?

When a user is done with their volume, they can delete the PVC objects from the API that allows reclamation of the resource. The reclaim policy for a PersistentVolume tells the cluster what to do with the volume after it has been released of its claim. Currently, volumes can either be Retained, Recycled, or Deleted.


3 Answers

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.

like image 131
apisim Avatar answered Oct 13 '22 06:10

apisim


You can monitorize them with kubelet prometheus metrics:

kubelet_volume_stats_available_bytes{persistentvolumeclaim="your-pvc"}
kubelet_volume_stats_capacity_bytes{persistentvolumeclaim="your-pvc"}
like image 37
Chus Avatar answered Oct 13 '22 06:10

Chus


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

like image 12
Brendan McGrath Avatar answered Oct 13 '22 07:10

Brendan McGrath