Home > Mobile >  Are volumes mounted to kubernetes pods by PersistentVolumeClaims different for replicas?
Are volumes mounted to kubernetes pods by PersistentVolumeClaims different for replicas?

Time:01-13

I have a PersistenceVolumeClaim defined by

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  storageClassName: "standard"
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

And the containers section of the deployment yaml looks like this

spec:
  containers:
  - name: my-container
    image: abc/xyz:1.2.3
    volumeMounts:
    - mountPath: /var/store
      name: mystore
  volumes:
  - name: mystore
    persistentVolumeClaim:
      claimName: my-pvc

I have a few questions about this set up.

  1. Do each replica of my pod get 1GB storage space (Assuming the PersistentVolume has enough space)?
  2. How would this behave if the pod replicas are on different kubernetes nodes?

Edit

I would like all replicas of my pod to have it's own storage (not a shared one). Is there a way to achieve this without creating a RWM volume?

CodePudding user response:

Do each replica of my pod get 1GB storage space (Assuming the PersistentVolume has enough space)?

No. Since you use one PersistentVolumeClaim, you will get one PersistentVolume.

How would this behave if the pod replicas are on different kubernetes nodes?

It will not work, unless you use a volume type that can be used from multiple nodes at once, with access mode ReadWriteMany or ReadOnlyMany. But you have declared ReadWriteOnce in your PersistentVolumeClaim, so it will likely not work.

I would like all replicas of my pod to have it's own storage (not a shared one). Is there a way to achieve this without creating a RWM volume?

Yes, you can use StatefulSet instead of Deployment, and use the volumeClaimTemplates:-field.

  • Related