2

I am trying to model stateful component/services (e.g. CouchBase, Postgres, etc) in Kubernetes. In Kubernetes, replication controller object requires a template for pod to cookie cut (replicate) pods. If the pod is for a stateful component, then the template will be required to include the persistent volume claim. If I specify a persistent claim in template of a replication controller, then that might (have not tried it, but logically) result in sharing of persistent volume claim between different pods and as a consequence resulting in conflict between multiple pods.

How to assign a different persistent volume claim to each pod when using replication controller for managing pods? How to model stateful components in Kubernetes using replication controller?

Anand Patel
  • 6,031
  • 11
  • 48
  • 67

2 Answers2

3

Today you would probably need to create a ReplicationController for each replica or component in your app. So if you have a 3 node replica of say Postgres, you would create 3 controllers for that.

You could look at helm (https://helm.sh/) to help out here as well which has addresses some of this for you up front by automating some of the pieces.

There is also a notion of PetSet which is being implemented and addresses this issue more. You can read up on some of those details here: https://github.com/kubernetes/kubernetes/issues/260

Steve Sloka
  • 3,444
  • 2
  • 22
  • 29
  • Hello; I also wanted to draw attention to the excellent answer here: http://stackoverflow.com/questions/41732819/why-statefulsets-cant-a-stateless-pod-use-persistent-volumes. It covers Stateful Sets and goes into more depth on why they're appropriate. Helpful to a rookie like me. – Laird Nelson Jan 20 '17 at 19:12
2

1 pv per pod matching it's network identity will work automatically with petset. It will be in alpha in 1.3, but it's yet undocumented (because 1.3 is not out yet). The closest you might find to docs right now are: https://github.com/kubernetes/kubernetes/issues/260#issuecomment-220395798

Docs should be up by EOW though.

Prashanth B
  • 4,833
  • 1
  • 19
  • 13