<p>I'm trying to define a shared persistent volume in k8s between two different deployments, and I've encountered some issues:</p>
<p>I have 2 pods for each deployment and between the deployments I'm trying to configure a shared volume - that mean that if I create a txt file in deplyment1/pod1 and I take a look in deplyment1/pod2 - I can't see the file.</p>
<p>The second issue is that I can't see the files in another deployment (deplyment2) - what's currently happening is that each pod created its own separated volume instead of sharing the same volume.</p>
<p>My goal, in the end, is to create a shared volume between the pods and the deployments.
It's important to note that I'm running on GKE.</p>
<p>Below are my current configurations</p>
<p>Deployment 1:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app1
  namespace: test
spec:
  selector:
    matchLabels:
      app: app1
  template:
    metadata:
      labels:
        app: app1
    spec:
      containers:
        - name: server
          image: app1
          ports:
            - name: grpc
              containerPort: 11111
          resources:
            requests:
              cpu: 300m
            limits:
              cpu: 500m
          volumeMounts:
            - name: test
              mountPath: /etc/test/configs
      volumes:
        - name: test
          persistentVolumeClaim:
            claimName: my-claim
</code></pre>
<p>Deployment 2:</p>
<pre class="lang-yaml prettyprint-override"><code>    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: app2
      namespace: test
    spec:
      selector:
        matchLabels:
          app: app2
      template:
        metadata:
          labels:
            app: app2
        spec:
          containers:
            - name: server
              image: app2
              ports:
                - name: http
                  containerPort: 22222
              resources:
                requests:
                  cpu: 300m
                limits:
                  cpu: 500m
              volumeMounts:
                - name: test
                  mountPath: /etc/test/configs
          volumes:
            - name: test
              persistentVolumeClaim:
                claimName: my-claim
</code></pre>
<p>Persistent Volume:</p>
<pre class="lang-yaml prettyprint-override"><code>    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: test-pv
      namespace: test
    spec:
      capacity:
        storage: 5Gi
      volumeMode: Filesystem
      accessModes:
      - ReadWriteMany
      persistentVolumeReclaimPolicy: Retain
      storageClassName: fast
      local:
        path: /etc/test/configs
      nodeAffinity:
        required:
          nodeSelectorTerms:
          - matchExpressions:
            - key: cloud.google.com/gke-nodepool
              operator: In
              values:
              - default-pool
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: my-claim
      namespace: test
      annotations:
        volume.beta.kubernetes.io/storage-class: fast
    spec:
      accessModes:
      - ReadWriteMany
      storageClassName: fast
      resources:
        requests:
          storage: 5Gi
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: fast
    provisioner: kubernetes.io/gce-pd
    parameters:
      type: pd-ssd
      fstype: ext4
      replication-type: regional-pd
</code></pre>
<p>and describe pv and pvc:</p>
<pre class="lang-sh prettyprint-override"><code>     $ kubectl describe pvc -n test
        Name:          my-claim
        Namespace:     test
        StorageClass:  fast
        Status:        Bound
        Volume:        test-pv
        Labels:        &lt;none&gt;
        Annotations:   pv.kubernetes.io/bind-completed: yes
                       pv.kubernetes.io/bound-by-controller: yes
                       volume.beta.kubernetes.io/storage-class: fast
        Finalizers:    [kubernetes.io/pvc-protection]
        Capacity:      5Gi
        Access Modes:  RWX
        VolumeMode:    Filesystem
        Mounted By:    &lt;none&gt;
        Events:        &lt;none&gt;
</code></pre>
<pre class="lang-sh prettyprint-override"><code>      $ kubectl describe pv -n test
        Name:              test-pv
        Labels:            &lt;none&gt;
        Annotations:       pv.kubernetes.io/bound-by-controller: yes
        Finalizers:        [kubernetes.io/pv-protection]
        StorageClass:      fast
        Status:            Bound
        Claim:             test/my-claim
        Reclaim Policy:    Retain
        Access Modes:      RWX
        VolumeMode:        Filesystem
        Capacity:          5Gi
        Node Affinity:
          Required Terms:
            Term 0:        cloud.google.com/gke-nodepool in [default-pool]
        Message:
        Source:
            Type:  LocalVolume (a persistent volume backed by local storage on a node)
            Path:  /etc/test/configs
        Events:    &lt;none&gt;
</code></pre>

Saar Wintrov
<p>GCE-PD CSI storage driver does not support <code>ReadWriteMany</code>. You need to use <code>ReadOnlyMany</code>. For <code>ReadWriteMany</code> you need to use GFS mounts.</p>
<p>From the <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/readonlymany-disks" rel="nofollow noreferrer">docs</a> on how to use persistent disks with multiple readers</p>
<p>Creating a <code>PersistentVolume</code> and <code>PersistentVolumeClaim</code></p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-readonly-pv
spec:
  storageClassName: &quot;&quot;
  capacity:
    storage: 10Gi
  accessModes:
    - ReadOnlyMany
  claimRef:
    namespace: default
    name: my-readonly-pvc
  gcePersistentDisk:
    pdName: my-test-disk
    fsType: ext4
    readOnly: true
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-readonly-pvc
spec:
  # Specify &quot;&quot; as the storageClassName so it matches the PersistentVolume's StorageClass.
  # A nil storageClassName value uses the default StorageClass. For details, see
  # https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class-1
  storageClassName: &quot;&quot;
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: 10Gi
</code></pre>
<p>Using the <code>PersistentVolumeClaim</code> in a Pod</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: pod-pvc
spec:
  containers:
  - image: k8s.gcr.io/busybox
    name: busybox
    command:
      - &quot;sleep&quot;
      - &quot;3600&quot;
    volumeMounts:
    - mountPath: /test-mnt
      name: my-volume
      readOnly: true
  volumes:
  - name: my-volume
    persistentVolumeClaim:
      claimName: my-readonly-pvc
      readOnly: true
</code></pre>
<p>Now, you can have multiple Pods on different nodes that can all mount this <code>PersistentVolumeClaim</code> in read-only mode. However, you can't attach persistent disks in write mode on multiple nodes at the same time</p>
