23

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.

Jonas
  • 121,568
  • 97
  • 310
  • 388
Vampire_D
  • 518
  • 1
  • 4
  • 10

4 Answers4

23

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.

Kav Latiolais
  • 246
  • 2
  • 4
7

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.

hxquangnhat
  • 255
  • 2
  • 6
2

There are many types of PV-s (e.g. various cloud storage). Each of them might have a different way of getting this information. 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.

I assume though that you are using Local PV-s. In this case your solution to run df -h inside a container is not bad. One other thing you could do is to run this command on the node which hosts the PV directly.

Dávid Molnár
  • 10,673
  • 7
  • 30
  • 55
  • 1
    thanks for your reply, actually the describe donot have usage storage. and I didnt use the Local PV, I am using the azure stroage. due to busybox is linux base, so the ```df -h``` could check the mount folder in busybox as my knowledge – Vampire_D Dec 13 '19 at 03:30
  • You could also monitor your storage account in Azure: https://azure.microsoft.com/en-us/documentation/articles/storage-monitor-storage-account/. – Dávid Molnár Dec 13 '19 at 06:42
  • yes, your correct. but as to company i am working on, the PaaS on azure are not visibility to devops, so I am just seeking a way in k8s. – Vampire_D Dec 13 '19 at 07:35
1

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
N K Shukla
  • 288
  • 1
  • 3
  • 12