<p>I am trying to understand what these settings do.<br>
PV - spec.capacity.storage<br>
PVC - spec.resources.requests.storage</p>
<p>I am trying to limit the amount of storage space that can be consumed by a pod i.e. a fixed size. Both of these settings take a setting like &quot;10G&quot;. Everything I have tried so far does not appear to impose a limit.</p>
<p>Can someone explain these settings or how I can limit the storage space used?</p>
<p>Thanks.</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: nfs-pv
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: nfs
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /mnt/Storage/nfs-test
    server: ip_address
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nfs-pvc
spec:
  storageClassName: nfs
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pv-pod
spec:
  volumes:
    - name: nginx-pv-storage
      persistentVolumeClaim:
        claimName: nfs-pvc
  containers:
    - name: nginx
      image: nginx
      ports:
        - containerPort: 80
          name: &quot;nginx-server&quot;
      volumeMounts:
        - mountPath: &quot;/usr/share/nginx/html&quot;
          name: nginx-pv-storage

$ kubectl describe pv nfs-pv
Name:            nfs-pv
Labels:          &lt;none&gt;
Annotations:     pv.kubernetes.io/bound-by-controller: yes
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    nfs
Status:          Bound
Claim:           default/nfs-pvc
Reclaim Policy:  Recycle
Access Modes:    RWX
VolumeMode:      Filesystem
Capacity:        10Gi
Node Affinity:   &lt;none&gt;
Message:
Source:
    Type:      NFS (an NFS mount that lasts the lifetime of a pod)
    Server:    ip_address
    Path:      /mnt/Storage/nfs-test
    ReadOnly:  false
Events:        &lt;none&gt;

$ kubectl describe pvc nfs-pvc
Name:          nfs-pvc
Namespace:     default
StorageClass:  nfs
Status:        Bound
Volume:        nfs-pv
Labels:        &lt;none&gt;
Annotations:   pv.kubernetes.io/bind-completed: yes
               pv.kubernetes.io/bound-by-controller: yes
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:      10Gi
Access Modes:  RWX
VolumeMode:    Filesystem
Used By:       nginx-pv-pod
Events:        &lt;none&gt;
</code></pre>
<p>So I am guessing the &quot;capacity&quot; setting does nothing recognizable.</p>

Dave Pearce
<blockquote>
<p>I am trying to limit the amount of storage space that can be consumed by a pod</p>
</blockquote>
<p>There's essentially three things here.  One is the size of the image itself; there's no way to limit this.  A second is volumes you mount into the container; this is for example the PersistentVolume you show, and by analogy you might think of it like plugging in an external USB disk that doesn't &quot;count against&quot; your internal hard drive storage.  The third is disk space used up by the container process while it's running, for things like temporary files or on-disk logs.</p>
<p>When you say &quot;limit the storage space of a container&quot; I think of that third option.  Kubernetes calls this <a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#setting-requests-and-limits-for-local-ephemeral-storage" rel="nofollow noreferrer">ephemeral storage</a> and you can assign resource limits to it the same way you can memory and CPU:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Pod
spec:
  containers:
    - name: nginx
      resources:
        limits:
          ephemeral-storage: 10Gi
</code></pre>
<p>For the example you show, you probably do not need an additional volume.  It can be a little tricky to copy content in and out of a volume, so you don't usually want to use a volume to hide things like the HTML content in an image.</p>
<p>A more typical example of these would be a database container.  You want persistent storage for the database data itself, that's capable of following the database pod around the cluster if it gets deleted and recreated.  A typical sequence there is</p>
<ol>
<li>The operator creates a StatefulSet to run the database</li>
<li>Kubernetes creates a PersistentVolumeClaim for each replica from the template in the StatefulSet, including the PVC's requested <code>storage</code> size</li>
<li>A <em>persistent volume provisioner</em> running as cluster infrastructure gets appropriate storage (for example, an AWS EBS volume) and records its details in a PersistentVolume</li>
</ol>
<p>So with this flow you don't directly create the PersistentVolume; but conversely you do specify the size you want that storage to be when you create the PersistentVolumeClaim.</p>
<p>Your setup uses NFS as a storage backend.  That's fine if you have an NFS server, but the metadata in the PersistentVolume/Claim doesn't imply any sort of disk quota on the NFS backend.  The PVC requests that at least 10 GiB of storage is available and the PV asserts it's there, but in reality you can probably use the full disk of the NFS server, however large it is.</p>
