<p>I'm trying to monitor Kubernetes PVC disk usage. I need the memory that is in use for Persistent Volume Claim. I found the command:</p>
<blockquote>
<p>kubectl get --raw / api / v1 / persistentvolumeclaims</p>
</blockquote>
<p>Return:</p>
<pre><code>&quot;status&quot;:{
            &quot;phase&quot;:&quot;Bound&quot;,
            &quot;accessModes&quot;:[
               &quot;ReadWriteOnce&quot;
            ],
            &quot;capacity&quot;:{
               &quot;storage&quot;:&quot;1Gi&quot;
            }
         }
</code></pre>
<p>But it only brings me the full capacity of the disk, and as I said I need the used one</p>
<p>Does anyone know which command could return this information to me?</p>

Danilo Marquiori
<p>+1 to <a href="https://stackoverflow.com/users/14425365/touchmarine">touchmarine's</a> answer however I'd like to expand it a bit and add also my three cents.</p>
<blockquote>
<p>But it only brings me the full capacity of the disk, and as I said I
need the used one</p>
</blockquote>
<p><code>PVC</code> is an abstraction which represents <strong>a request for a storage</strong> and simply doesn't store such information as disk usage. As a higher level abstraction it doesn't care at all how the underlying storage is used by its consumer.</p>
<p>@touchmarine, Instead of using a <code>Pod</code> whose only function is to <code>sleep</code> and every time you need to check the disk usage you need to attach to it maually, I would propose to use something like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      volumes:
      - name: media
        persistentVolumeClaim:
          claimName: media
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: &quot;/data&quot;
          name: media
      - name: busybox
        image: busybox
        command: [&quot;/bin/sh&quot;]
        args: [&quot;-c&quot;, &quot;while true; do du -sh /data; sleep 10;done&quot;]
        volumeMounts:
        - mountPath: &quot;/data&quot;
          name: media
</code></pre>
<p>It can be of course a single-container <code>busybox</code> <code>Pod</code> as in @touchmarine's example but here I decided to to show also how it can be used as a sidecar running next to <code>nginx</code> container within a single <code>Pod</code>.</p>
<p>As it runs a simple bash script - an infinite while loop, which prints out current disk usage to the standard output it can be read with <code>kubectl logs</code> without a need of using <code>kubectl exec</code> and attaching to the <code>Pod</code>:</p>
<pre><code>$ kubectl logs nginx-deployment-56bb5c87f6-dqs5h busybox
20.0K   /data
20.0K   /data
20.0K   /data
</code></pre>
<p>I guess it can be also used more effectively to configure some sort of monitoring of disk usage.</p>
