1

So yes, StatefulSet helps preserve the order and name of the pod, but what is it that it does extra (or different) that is advantageous over a regular Deployment with respect to volumes.

I see many examples of master/slave setup for databases as a use case for StatefulSet, but can't that problem be solved with just a Deployment (replicas=1) for the master and a Deployment (replicas=<multiple>) for the slaves. For volumes just create a PV/PVC.

Can someone please let me know what is the difference with respect to volumes?

Gurleen Sethi
  • 3,162
  • 6
  • 26
  • 48

1 Answers1

1

So yes, StatefulSet helps preserve the order and name of the pod, but what is it that it does extra (or different) that is advantageous over a regular Deployment with respect to volumes.

With a StatefulSet each Pod get its own PersistentVolumeClaim, but with Deployment all Pods use the same PersistentVolumeClaim.

StatefulSet has volumeClaimTemplates that creates volumes for you from the template and it adds -<ordinal> on the name for PersistentVolumeClaims, so a name with my-pvc will be my-pvc-0 and my-pvc-1 if the StatefulSet has replicas: 2.

I see many examples of master/slave setup for databases as a use case for StatefulSet, but can't that problem be solved with just a Deployment (replicas=1) for the master and a Deployment (replicas=) for the slaves. For volumes just create a PV/PVC.

Yes, that would probably work - for testing and development. But it would not be recommended in a production environment. Typically in a cloud (and Kubernetes) environment, you use a Database that use three replicas and that has an instance in every Availability Zone - this is easier to manage with a single StatefulSet with replicas: 3 and proper PodAffinity configuration.

Jonas
  • 121,568
  • 97
  • 310
  • 388