Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying stateful applications in Kubernetes

Tags:

kubernetes

I'm getting acquainted with Kubernetes, and haven't found simple solution for deploying stateful services in Kubernetes.

  • Every pod has to be bootstrapped with contact points (list of other pod IPs), which can't be load balanced (i'm afraid of split-brain in case of bad luck: in worst case load-balancer may load-balance every pod to itself, making several self-enclosed clusters of one node)
  • Every pod has to have persistent storage that, in worst case, has to be accessed manually (e.g. consul's peers.json)
  • Every pod should be reconfigurable; if i've forgot to do something with my consul cluster, rebuilding it from scratch would simply result in downtime. In case kubernetes prevents this, feel free to tell me, i'm still not familiar enough with deployment mechanics.
  • Increasing service cluster dynamically with newly-configured instances and then draining older ones may be highly undesired (i'm not consul expert, but from my point of view that drops split-brain protection in consul cluster).

AFAIK the most applicable thing is Pet Set, however, it is still in alpha and can only be deleted completely; also, i don't feel i understand how persistent volumes should be managed to survive Pet Set recreation. Another option i've came up with is splitting service deployments into bootstrap-node deployment, bootstrap-node service and all-other-nodes deployment, which allows me to use bootstrap-node service as a contact point (that's not completely safe, though).

What are the popular approaches for this case and what pros and cons do they have?

like image 685
Etki Avatar asked Aug 09 '16 13:08

Etki


People also ask

Is Kubernetes good for stateful applications?

Kubernetes has become the best orchestration platform for stateful applications. Using the Kubernetes constructs like persistent volume, StatefulSets and DaemonSets, you can efficiently scale and manage the stateful application.

What is stateful deployment in Kubernetes?

StatefulSet is the workload API object used to manage stateful applications. Manages the deployment and scaling of a set of Pods, and provides guarantees about the ordering and uniqueness of these Pods. Like a Deployment, a StatefulSet manages Pods that are based on an identical container spec.

Can you use a deployment for stateful applications?

Deployments are used for stateless applications, StatefulSets for stateful applications. The pods in a deployment are interchangeable, whereas the pods in a StatefulSet are not. Deployments require a service to enable interaction with pods, while a headless service handles the pods' network ID in StatefulSets.

Is Kubernetes stateful or stateless?

Topics: Cloud Volumes ONTAP, Kubernetes, Advanced Though Kubernetes storage has always supported stateless applications—which are horizontally scalable due to the interchangeability of each pod—stateful applications require stronger guarantees for the storage they use.


1 Answers

If you're looking at a set number of Pods in your stateful cluster in the Kubernetes cluster, PetSets (StatefulSets I believe it is called now) is the answer... or you can define a Service per Pod to achieve the same.

For Pods to be aware of other Pods's IPs, you can use Headless Services, which provide you with the list of IPs associated with a label.

For Storage, if you use emptyDir, you have local storage but you lose it when the Pod is removed / re-scheduled.

I use Zookeeper in Kubernetes and it is a bit of a pain to setup, but Zookeeper provides a 'reconfigure' API which allows to reconfigure the cluster when a node changes, so it is fairly easy to redefine the cluster on startup of a new node when a Pod is rescheduled. I'm not sure if Consul has the same type of feature, but it probably does.

like image 197
MrE Avatar answered Oct 02 '22 11:10

MrE