<p>I am struggling to understand the concept of the Capacity parameter on the PersistentVolume, and similarly the storage Request on the PersistentVolumeClaim when dealing with ReadOnlyMany storage. If the storage is mounted in read only- what exactly is the Capacity/Request in relation to? </p>

<p>i.e. </p>

<pre><code>spec:
  storageClassName: manual
  capacity:
    storage: 50Gi
  accessModes:
    - ReadOnlyMany
  hostPath:
    path: "/foo/bar"


spec:
  storageClassName: manual
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: 1Mi
</code></pre>

<p><strong>PersistentVolume</strong>(PV) is an object usually created by an administrator or auto-provisioned by a cloud provider.  </p>

<p>You can imagine it as flash drives laying on a table and available for claiming.  </p>

<p><strong>PersistentVolumeClaim</strong>(PVC) is a minimum specification that PV should comply with. </p>

<p>Continuing the flash drive analogy, we can imagine that we need a flash drive that is:   </p>

<ol>
<li>red, (color=red) (strict clause)  </li>
<li>Produced in the USA (manufactured=usa) (strict clause)  </li>
<li>Has a minimum capacity of 2Gb (capacity>=2gb) (I put “more or equal” here because that is how kubernetes selects PV by capacity) (not so strict)  </li>
</ol>

<p>(Workaround: You can put capacity value to label and use a selector to filter only the size you want, not less, not more. We skip it for now)  </p>

<p>And we can find on the table two flash drives that are:  </p>

<ol>
<li>red, (exact match) (don’t care about other colors)  </li>
<li>Manufactured in the USA (exact match) (don’t care about those produced in China or Vietnam)  </li>
<li>Have a capacity of 16 Gb and 4Gb  </li>
</ol>

<p>As soon as we need only 2Gb, we take the flash-drive with 4Gb capacity, which is closer to our needs.  </p>

<p>After you choose the correct “flash drive” (bound PV to your container), you can use its full capacity (4Gb available) even if your claim was smaller (2Gb would be enough).   </p>

<p>But when you take the flash drive from the table, nobody else can claim it (in case you took the last one). In kubernetes, PV and PVC bind as 1-to-1. So, if you have one PV of 50Gb and two claims of 5GB, only one claim will be satisfied.  </p>

<p>You can imagine that <strong>ReadOnlyMany</strong> and <strong>ReadWriteOnce</strong> mode in PV as a pile of CD or DVD disks with the same data. You can write something on it and then anybody can read it many times. <strong>ReadWriteOnce</strong> PV can be bound to only one container with write access, but still can be bound to many containers with read only access (take one disk from the pile, there are more of them).   </p>

<p>There is not much sense to search information by size in our case, so in PVC you can use any number that is smaller than expected from PV, and use selector, access mode, and storage class to find exactly what you need.  </p>

<p>For example, you can create PV that has NFS share under the hood:  </p>

<pre><code>apiVersion: v1  
kind: PersistentVolume  
metadata:  
  name: pv-with-data  
  labels:  
    version: stable  
    capacity: 50Gi  &lt;-(workaround I’ve mentioned before)  
spec:  
  capacity:  
    storage: 50Gi  
  accessModes:  
  - ReadWriteOnce  
  - ReadOnlyMany  &lt;- (yes, you can have several modes in PV specification)  
  persistentVolumeReclaimPolicy: Retain  
  nfs:  
    path: /opt/export  
    server: 10.10.0.10  
</code></pre>

<p>The PVC would be something like this:  </p>

<pre><code>apiVersion: v1  
kind: PersistentVolumeClaim  
metadata:  
  name: data-claim  
spec:  
  accessModes:  
  - ReadWriteOnce  
  resources:  
    requests:  
      storage: 25Gi  
  selector:  
    matchLabels:  
      version: "stable"  
    matchExpressions:  
    - key: capacity  
      operator: In  
      values: [25Gi, 50Gi]  
</code></pre>

<p>More (boring) information can be found in the documentation:  </p>

<p><a href="https://kubernetes.io/docs/concepts/storage/volumes/" rel="noreferrer">Volumes</a><br>
<a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="noreferrer">Persistent Volumes</a><br>
<a href="https://kubernetes.io/docs/concepts/storage/storage-classes/" rel="noreferrer">Storage Classes</a><br>
<a href="https://kubernetes.io/docs/concepts/storage/dynamic-provisioning/" rel="noreferrer">Dynamic Volume Provisioning</a><br>
<a href="https://www.packtpub.com/virtualization-and-cloud/mastering-kubernetes" rel="noreferrer">Gigi Sayfan, Mastering Kubernetes</a>  </p>
