<p>This may be a dumb question but I haven't found much online and want to clarify this. </p>

<p>Given two deployments A and B, both with <em>different</em> container images:</p>

<ul>
<li>They're deployed in two different pods(different rc, svc etc.) in a K8/OpenShift cluster.</li>
<li>They both need to access the same volume to read files (let's leave locking out of this for now) or at least the same directory structure in that volume.</li>
<li>Mounting this volume using a PVC (Persistent Volume Claim) backed by a PV (Persistent Volume) configured against a NFS share.</li>
</ul>

<p>Can I confirm that the above would actually be possible? I.e. two <em>different</em> pods connected to the same volume with the same PVC. So they both are reading from the same volume.</p>

<p>Hope that makes sense...</p>

<p>TL;DR
You can share PV and PVC within the same project/namespace for shared volumes (nfs, gluster, etc...), you can also access your shared volume from multiple project/namespaces but it will require project dedicated PV and PVCs, as a PV is bound to single project/namespace and PVC is project/namespace scoped.</p>

<p>Below I've tried to illustrate the current behavior and how PV and PVCs are scoped within OpenShift.  These are simple examples using NFS as the persistent storage layer.</p>

<p>the accessModes at this point are just labels, they have no real functionality in terms of controlling access to PV.  Below are some examples to show this</p>

<p>the PV is global in the sense that it can be seen/accessed by any project/namespace, HOWEVER once it is bound to a project, it can then only be accessed by containers from the same project/namespace</p>

<p>the PVC is project/namespace specific (so if you have multple projects you would need to have a new PV and PVC for each project to connect to the shared NFS volume - can not reuse the PV from first project)</p>

<p><strong>Example 1:</strong><br>
I have 2 distinct pods running in "default" project/namespace, both accessing the same PV and NFS exported share.  Both mount and run fine.</p>

<pre><code>[root@k8dev nfs_error]# oc get pv
NAME      LABELS    CAPACITY   ACCESSMODES   STATUS    CLAIM  REASON    AGE
pv-nfs    &lt;none&gt;    1Gi        RWO           Bound default/nfs-claim             3m


[root@k8dev nfs_error]# oc get pods    &lt;--- running from DEFAULT project, no issues connecting to PV
NAME              READY     STATUS    RESTARTS   AGE
nfs-bb-pod2-pvc   1/1       Running   0          11m
nfs-bb-pod3-pvc   1/1       Running   0          10m
</code></pre>

<p><strong>Example 2:</strong><br>
I have 2 distinct pods running in "default" project/namespace and attempt to create another pod using the same PV but from a new project called <code>testproject</code> to access the same NFS export.  The third pod from the new <code>testproject</code> will not be able to bind to the PV as it is already bound by <code>default</code> project.</p>

<pre><code>[root@k8dev nfs_error]# oc get pv
NAME      LABELS    CAPACITY   ACCESSMODES   STATUS    CLAIM  REASON    AGE
pv-nfs    &lt;none&gt;    1Gi        RWO           Bound default/nfs-claim             3m


[root@k8dev nfs_error]# oc get pods    &lt;--- running from DEFAULT project, no issues connecting to PV
NAME              READY     STATUS    RESTARTS   AGE
nfs-bb-pod2-pvc   1/1       Running   0          11m
nfs-bb-pod3-pvc   1/1       Running   0          10m
</code></pre>

<p>** Create a new claim against the existing PV from another project (testproject) and the PVC will fail</p>

<pre><code>[root@k8dev nfs_error]# oc get pvc 
NAME        LABELS    STATUS    VOLUME    CAPACITY   ACCESSMODES   AGE
nfs-claim   &lt;none&gt;    Pending                                      2s
</code></pre>

<p>** nfs-claim will never bind to the pv-nfs PV because it can not see it from it's current project scope</p>

<p><strong>Example 3:</strong></p>

<p>I have 2 distinct pods running in the "default" project and then create another PV and PVC and Pod from <code>testproject</code>.  Both projects will be able to access the same NFS exported share but I need a PV and PVC in each of the projects.  </p>

<pre><code>[root@k8dev nfs_error]# oc get pv
NAME      LABELS    CAPACITY   ACCESSMODES   STATUS     CLAIM                    REASON    AGE
pv-nfs    &lt;none&gt;    1Gi        RWX           Bound     default/nfs-claim                  14m
pv-nfs2   &lt;none&gt;    1Gi        RWX           Bound     testproject/nfs-claim2             9m



[root@k8dev nfs_error]# oc get pods --all-namespaces
NAMESPACE     NAME              READY     STATUS    RESTARTS   AGE
default       nfs-bb-pod2-pvc   1/1       Running   0          11m
default       nfs-bb-pod3-pvc   1/1       Running   0          11m
testproject   nfs-bb-pod4-pvc   1/1       Running   0          15s
</code></pre>

<p>** notice, I now have three pods running to the same NFS shared volume across two projects, but I needed two PV's as they are bound to a single project, and 2 PVC's, one for each project and the NFS PV I am trying to access</p>

<p><strong>Example 4:</strong></p>

<p>If I by-pass PV and PVC, I can connect to the shared NFS volumes directly from any project using the nfs plugin directly</p>

<pre><code>volumes:
- name: nfsvol
  nfs:
    path: /opt/data5
    server: nfs1.rhs
</code></pre>

<p>Now, the volume security is another layer on top of this, using supplementalGroups (for shared storage, i.e. nfs, gluster, etc...), admins and devs should further be able to manage and control access to the shared NFS system.</p>

<p>Hope that helps</p>
