Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an efficient way to check the usage for PV/PVC in Kubernetes

For example, I have 50 Gib PV/PVC and grant to one Pod, I just want to check usage of the storage

The way I am just following is to set up a busybox pod with mounting the same PVC, then exec into the busybox to run df -h to check the storage.

I just want to know if there is an efficient way to do the same thing.

like image 465
Vampire_D Avatar asked Dec 12 '19 07:12

Vampire_D


People also ask

How do you check PV utilization in Kubernetes?

You could always use kubectl describe pv <pv-name> or kubectl get pv <pv-name> -o yaml . This might give you some information about the current state of the PV, but it might lack the information you need.

How do you check data in PVC Kubernetes?

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 do you check PVC logs in Kubernetes?

To get the usage, create a debugging pod which will use your PVC, from which you will check the usage. This should work depending on your storage provider. Apply the above manifest with kubectl apply -f volume-size-debugger. yaml , and run a shell inside it with kubectl exec -it volume-size-debugger sh .

What is the difference between PV and PVC in Kubernetes?

The Difference Between PVs and PVCs in KubernetesPVs are created by the cluster administrator or dynamically by Kubernetes, whereas users/developers create PVCs. PVs are cluster resources provisioned by an administrator, whereas PVCs are a user's request for storage and resources.


3 Answers

Depending on how often you need to do this you might look at the df-pv plugin for kubectl https://github.com/yashbhutwala/kubectl-df-pv

It does exactly what you are asking across all the pvs in a namespace or cluster. Once you've got it installed, just run kubectl df-pv and you are set.

like image 113
Kav Latiolais Avatar answered Sep 19 '22 08:09

Kav Latiolais


You can try the below set of commands, I checked on AKS and found out it to be working fine.

kubectl get pods -n namespace1

Pick the pod_name currently using or mapped to the PV/PVC (Persistent Volume Claims) and since I used the mount directory on the PV hence I have used /mount to check its details & replace {pod_name} with actual pod_name.

kubectl exec -it {pod_name} -n namespace1 bash

df -h

ls -l /mount
like image 43
N K Shukla Avatar answered Sep 22 '22 08:09

N K Shukla


Unfortunately we don't have this at the moment. What I often do is querying on Prometheus (because I have a Prom cluster there) for the metrics kubelet_volume_stats_used_bytes for the information.

Or in the harder way, you can write an operator to watch a CRD which wraps the PVC and to display the usage of the PVC.

like image 36
hxquangnhat Avatar answered Sep 18 '22 08:09

hxquangnhat