David Maze :
You should usually use a volume claim template with a StatefulSet. As you note in the question, this will create a new PersistentVolumeClaim (and a new PersistentVolume) for each replica. Data is not shared, except to the extent the container process knows how to replicate data between its replicas. If a StatefulSet Pod is deleted and recreated, it will come back with the same underlying PVC and the same data, even if it is recreated on a different Node.\nspec:\n volumeClaimTemplates:\n - metadata:\n name: data\n spec:\n accessModes: [ReadWriteOnce]\n resources:\n requests:\n storage: 1Gi\n template:\n spec:\n containers:\n - name: name\n volumeMounts:\n - name: data\n mountPath: /data\n\nYou're allowed to manually create a PVC and attach it to the StatefulSet Pods\n# not recommended -- one PVC shared across all replicas\nspec:\n template:\n spec:\n volumes:\n - name: data\n persistentVolumeClaim:\n claimName: manually-created-pvc\n containers:\n - name: name\n volumeMounts:\n - name: data\n mountPath: /data\n\nbut in this case the single PVC/PV will be shared across all of the replicas. This often doesn't work well: things like database containers have explicit checks that their storage isn't shared, and there is a range of concurrency problems that are possible doing this. This also can prevent pods from starting up since the volume types that are straightforward to get generally only support a ReadWriteOnce access mode; to get ReadWriteMany you need to additionally configure something like an NFS server outside the cluster.",
2022-05-16T11:51:47
Harsh Manvar :
i am not sure which example you were following and checked that scenario however yes PV and PVC is 1:1 mapping.\nUsually, PVC gets attached to POD with access mode ReadWriteOnly which mean only one pod can do ReadWrite.\nThe scenario that you have might be seen could be something like there is a single PVC and single PV attach to multiple replicas which could be due to ReadWriteMany.\n\nA PersistentVolumeClaim (PVC) is a request for storage by a user. It\nis similar to a Pod. Pods consume node resources and PVCs consume PV\nresources. Pods can request specific levels of resources (CPU and\nMemory). Claims can request specific size and access modes (e.g., they\ncan be mounted ReadWriteOnce, ReadOnlyMany or ReadWriteMany, see\nAccessModes).\n\nRead more about access mode here : https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes\nNFS, EFS and other type of storage support the ReadWriteMany access mode.",
2022-05-15T19:15:33