I would like to understand if through PVC/PV a pod that is using a volume after a failure will be always re-attached to the same volume or not. Essentially I know that this can be a case for Statefulset but I am trying to understand if this can be also achieved with PVC and PV. Essentially assuming that a Pod_A is attached to Volume_X, then Pod_A fails but in the meantime a Volume_Y was added to the cluster that can potentially fulfil the PVC requirements. So what does it happen when Pod_A is re-created, does it get always mounted to Volume_X or is there any chance that it gets mounted to the new Volume_Y?
-
Are you talking about a single pod or a deployment? A deployment uses one specific PVC. Therefore, each pod of this deployment will use the same PVC. Keep in mind that if you need `RWX` access, the backing storage type needs to support this access mode. – Turing85 Oct 24 '21 at 19:44
-
Ok. So let's say I have 3 Pods in the deployment and they all fail at same time. When they are restarted each of them will "randomly" pickup one of the 3 storages previously created, right? Unless I use a Statefulset for which I can associated a Pod instance/identity to a specific volume instance, right? – toto' Oct 24 '21 at 19:51
-
2If we have three pods in the same deployment, then these three pods will use the same PVC, i.e. the "same storage". If we need three separate PVC for those three pods, then those three pods have an identity - or state - and we need a stateful set. We can then use `VolumeClaimTemplate`s to generate a PVC for each pod in the stateful set. – Turing85 Oct 24 '21 at 19:58
-
Am I correct that if (the 3) Pods have identities then even if the PVC is common in the deployment manifest then the Pods are getting different volumes and always mapped to the same (after a restart)? Or do I need to create 3 different PVC, hence 3 different deployment manifests? – toto' Oct 25 '21 at 05:23
-
2If the three pods should have three separate "storage"s, they need separate pvcs. That is what `VolumeClaimTemplate`s in a `StatefulSet` are for. – Turing85 Oct 25 '21 at 15:10
1 Answers
a pod that is using a volume after a failure will be always re-attached to the same volume or not
yes, the Pod will be re-attached to the same volume, because it still has the same PVC declared in its manifest.
Essentially assuming that a Pod_A is attached to Volume_X, then Pod_A fails but in the meantime a Volume_Y was added to the cluster that can potentially fulfil the PVC requirements.
The Pod still has the same PVC in its manifest, so it will use the same volume. But if you create a new PVC, it might be bound to the new volume.
So what does it happen when Pod_A is re-created, does it get always mounted to Volume_X or is there any chance that it gets mounted to the new Volume_Y?
The Pod still has the same PVC in its manifest, so it will use the volume that is bound by that PVC. Only when you create a new PVC, that claim can be bound the new volume.

- 121,568
- 97
- 310
- 388