K8s PVC: obtain the utilization state of PCV

10/14/2021

I'm working on a k8s namespace environment and I have a pod and its pvc deployed in it.\ When the pod transfers data on PVC I would know the percentage of memory used and free. There is a way?

-- Giuseppe Percuoco
kubernetes
kubernetes-pvc

1 Answer

10/18/2021

You can probably use kubedf (it supports most KaaS) script to show PVC usage. It only requires kubectl proxy to be running.


I will create an example to illustrate how it may work.

First, we need to download this script:

$ wget https://gist.githubusercontent.com/redmcg/60cfff7bca6f32969188008ad4a44c9a/raw/e5c5722e7b4a5725afe9217ebd05fb33a11d4571/kubedf

$ ls
kubedf

$ chmod a+x kubedf

After a successful installation, we nee to run kubectl proxy:

$ kubectl proxy
Starting to serve on 127.0.0.1:8001

And from another terminal window, we can test how it works. I have two PV and PVC:

$ kubectl get pv,pvc
NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM               STORAGECLASS   REASON   AGE
persistentvolume/pvc-52db08b6-dbb0-4fd7-b5a3-f828bf83f5c5   1Gi        RWO            Delete           Bound    default/myclaim-2   standard                33m
persistentvolume/pvc-db341238-8e7c-425c-856d-546589fa8c69   1Gi        RWO            Delete           Bound    default/myclaim     standard                43m

NAME                              STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/myclaim     Bound    pvc-db341238-8e7c-425c-856d-546589fa8c69   1Gi        RWO            standard       43m
persistentvolumeclaim/myclaim-2   Bound    pvc-52db08b6-dbb0-4fd7-b5a3-f828bf83f5c5   1Gi        RWO            standard       33m

Let's use kubedf to show PVC usage:

$ ./kubedf -h
PVC       Size Used Avail Use%
myclaim   974M 101M  858M  10%
myclaim-2 974M 301M  658M  31%
-- matt_j
Source: StackOverflow