<p>My pod declares two different volumes.</p>
<p>I use some definition templating, and depending on the environment in some cases I would like to reuse the same claim for the two volumes.</p>
<p>This results in an error:</p>
<pre><code>    Unable to mount volumes for pod &quot;task-pv-pod_&lt;...&gt;&quot;: timeout expired waiting for volumes to attach/mount for pod &quot;&lt;...&gt;&quot;/&quot;task-pv-pod&quot;. list of unattached/unmounted volumes=[task-pv-storage1]
</code></pre>
<ul>
<li>It works fine with two different claims.</li>
<li>It is possible to reuse the same claim in several pods.</li>
</ul>
<p>This is a simplified pod definition:</p>
<pre><code>kind: Pod
apiVersion: v1
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: task-pv-storage1
      persistentVolumeClaim:
       claimName: task-pv-claim
    - name: task-pv-storage2
      persistentVolumeClaim:
       claimName: task-pv-claim
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: &quot;http-server&quot;
      volumeMounts:
        - mountPath: &quot;/usr/share/nginx/html&quot;
          name: task-pv-storage1
        - mountPath: &quot;/usr/share/nginx/something-else&quot;
          name: task-pv-storage2
</code></pre>
<p>So why is it not working?</p>

<p>To answer your question "is it possible to use the same claim in several pods?", let's take a look at different claim attach access modes:</p>

<p>When you create a PVC with the default settings, you are creating a Persistent Volume and a Claim that sits on top of it, with the attach access mode <code>ReadWriteOnce</code>. </p>

<blockquote>
  <p>ReadWriteOnce – the volume can be mounted as read-write by a single node</p>
</blockquote>

<p>So this claim can only be mounted on pods on the same node. There is a workaround to be able to mount this volume onto multiple pods. One is to schedule all of your pods on the same node, which technically defeats the purpose of using container orchestration. This could be achieved by <a href="https://kubernetes.io/docs/concepts/configuration/assign-pod-node/" rel="noreferrer">assigning pods to nodes</a>. Read the linked doc for details.</p>

<p>Another method is to use disk persistent volumes / NFS. Depending on the cloud provider you are using there are different FileSystem provisioners you can use. </p>

<ul>
<li>AWS: <a href="https://github.com/helm/charts/tree/master/stable/efs-provisioner" rel="noreferrer">EFS Provisioner - helm</a></li>
<li>GKE: <a href="https://medium.com/platformer-blog/nfs-persistent-volumes-with-kubernetes-a-case-study-ce1ed6e2c266" rel="noreferrer">GCE NFS Disk</a></li>
<li>Other cloud providers: <a href="https://github.com/helm/charts/tree/master/stable/nfs-server-provisioner" rel="noreferrer">NFS Server Provisioner</a></li>
</ul>

<p>This way you can change your access mode to <code>ReadWriteMany</code>:</p>

<blockquote>
  <p>ReadWriteMany – the volume can be mounted as read-write by many nodes</p>
</blockquote>

<p>With this access policy you can mount your volume onto multiple pods in your cluster regardless of the node they are running on.</p>
