<p>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. </p>

<p>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?</p>

<p>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. </p>

<p>You could look at helm (<a href="https://helm.sh/" rel="nofollow">https://helm.sh/</a>) to help out here as well which has addresses some of this for you up front by automating some of the pieces.</p>

<p>There is also a notion of <code>PetSet</code> which is being implemented and addresses this issue more. You can read up on some of those details here: <a href="https://github.com/kubernetes/kubernetes/issues/260" rel="nofollow">https://github.com/kubernetes/kubernetes/issues/260</a></p>
