4

Suppose I have a resource foo which is a statefulset with 3 replicas. Each makes a persistent volume claim.

One of the foo pods (foo-1) dies, and a new one starts in its place. Will foo-1 be bound to the same persistent volume that the previous foo-1 had before it died? Will the number of persistent volume claims stay the same or grow?

This edge case doesn't seem to be in the documentation on StatefulSets.

FrobberOfBits
  • 17,634
  • 4
  • 52
  • 86
  • Just re-read the docs and I think it's (more or less clearly) defined in https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-identity in the "Stable Storage" section, or? – Michael Hausenblas Jun 18 '18 at 12:30

1 Answers1

4

Yes you can. A PVC is going to create a disk on GCP, and add it as secondary disk to the node in which the pod is running.

Upon deletion of an individual pod, K8s is going to re-create the pod on the same node it was running. If it is not possible (say the node no longer exists), the pod will be created on another node, and the secondary disk will be moved to that node.

suren
  • 7,817
  • 1
  • 30
  • 51
  • Does it matter if the pod is recreated on the same node? Does this answer imply that the persistenvolume claim is node specific? Shouldn't it be possible that the pod starts up on some other node but is still bound to the same volume? – FrobberOfBits Jun 18 '18 at 12:31
  • I actually just made a full test, and yes, you can. So, but default K8s always was trying to create the pod on the same node where the PVC is provisioned (that's great). What's even better is that if I cordon the node, kill the pod and create it (in which case it gets re-created on another node), the PVC moves with it. – suren Jun 18 '18 at 15:12
  • 1
    Done. Sorry about it. – suren Jun 18 '18 at 15:42