<p>In my StatefulSet deployment specification, I have 'replicas' defined as 2. Now I want to use Persistent Volume (PV) and Persistent Volume Claims (PVC), for which I created one PV (dynamic provisioning using StorageClass) and one PVC which I then used in my deployment spec. I am testing the deployment on AWS.</p>

<p>The problem is that only one node is able to get attached to the PV using the PVC. Even if I create multiple PVs and PVCs for each node, I am not sure how to use them in the deployment spec so that each node picks a different PV.</p>

<p>Error:</p>

<pre><code>Multi-Attach error for volume "pvc-ec99e704-f72e-11e7-87a6-065468f047a0" Volume is already exclusively attached to one node and can't be attached to another
</code></pre>

<p>Any pointer will help! </p>

<p>I think there are two issues you're facing here.</p>

<p>For starters, AWS EBS can be attached to one node exclusively, o can't have the same PVC/PV couple for multiple PODs (what is called a ROX or RWX mode).</p>

<p>Secondly, for scaled deployments/statefullsets etc. there is a special way to declare PVC in a way that is "dynamic" called volumeClaimTemplate.</p>

<pre><code>  volumeClaimTemplates:
  - metadata:
      name: myname
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
</code></pre>

<p>With this, whenever scaled, your pods will create/remove matching PVCs automatically.</p>

<p>This use case really calls for support of automatic PV provisioning though, to be really usefull, meaning you either need to be on a supported cloud provider or use another mechanism like GlusterFS with <a href="https://github.com/heketi/heketi" rel="nofollow noreferrer">Heketi</a></p>
