Connecting 2 different statefulSets to the same PV

11/5/2018

I have a statefulSet that has a VolumeClaim.

The volume section of StatefulSet1 is

  volumes:
  - name: artifact
    persistentVolumeClaim:
      claimName: artifacts

The PVC definition is

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: artifacts
spec:
  accessModes:
    - "ReadWriteOnce"
  resources:
    requests:
      storage: "5Gi"
  storageClassName: default

Now when I spin up StatefulSet1, everything is ok. The pod get the claim and is successfully mounted.

Now I want to bring up another Stateful set i.e. StatefulSet2 which needs to attach to the PV.

So my volume section of StatefulSet2 is the same.

  volumes:
  - name: artifact
    persistentVolumeClaim:
      claimName: artifacts

But when I spin up StatefulSet2, my original PVC goes into terminating state.

kubectl get pvc artifacts
NAME                STATUS        VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
artifacts           Terminating   pvc-b55f729d-e115-11e8-953e-02000a1bef39   5Gi       RWO            rbd-mario      31m

And the new pod is continuously in Pending state.

Not sure what Im doing wrong here. But my aim is to connect multiple StatefulSets/Pods to the same PV.

--
kubernetes
kubernetes-pvc

1 Answer

11/5/2018

The accessMode for this PVC is set to ReadWriteMany so the kubernetes allows mounting this PVC on multiple pods

https://docs.portworx.com/scheduler/kubernetes/shared-volumes.html

https://docs.okd.io/latest/install_config/storage_examples/shared_storage.html

More likely this should work:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: artifacts
spec:
  accessModes:
    - "ReadWriteMany"
  resources:
    requests:
      storage: "5Gi"
  storageClassName: default
-- Ijaz Ahmad Khan
Source: StackOverflow