How to use PersistentVolumeClaim if replicas attribute value is greater than 1?

1/11/2018

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.

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.

Error:

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

Any pointer will help!

-- lex
kubernetes

1 Answer

1/12/2018

I think there are two issues you're facing here.

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).

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

  volumeClaimTemplates:
  - metadata:
      name: myname
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

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

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 Heketi

-- Radek 'Goblin' Pieczonka
Source: StackOverflow