How to model stateful components in Kubernetes using replication controller?

6/16/2016

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
kubernetes

2 Answers

6/16/2016

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
Source: StackOverflow

6/20/2016

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
Source: StackOverflow