May 18, 2017 | by Michael Hausenblas
I oftentimes hear folks stating that Kubernetes is great for stateless applications but when it comes to stateful applications, questions like: 'Can it be done?' or even 'Should it be done?' come up frequently. In this post, I'd like to offer a slightly more differentiated point of view and provide you with some resources that might help you dealing with stateful applications.
When you see or hear the term 'stateful application' you might be thinking: right, I know, a database! Before we get to this, allow me to step back a bit and introduce two orthogonal concepts:
Putting these two concepts together, we arrive at something like the following:
Now let's have a closer look at the examples in above figure:
One has a certain degree of freedom where to place an app, for example, in the case of the shopping basket the requirements could be such that you need to make sure the items in the basket are available across sessions and a pure in-memory solution is hence not allowed.
Another aspect to consider when designing stateful applications revolves around the primary location of the data. For example, if the initial state is kept external, as was the case with the web server, a volume backed by the filesystem of a node is sufficient. If, however, the app itself is the authoritative data source, for example, a Wordpress blog using MySQL, you might want to make sure that the data survives node failures and hence prefer a persistent volume backed by NFS or EBS.
Last but not least, since Kubernetes 1.5, you have a dedicated controller for stateful applications at your disposal: StatefulSet. Strictly speaking, this feature was already around longer but up to 1.4 this Kubernetes object was called PetSet
.
A StatefulSet
, as the name suggests, exists to help you setting up and operating stateful applications and distributed systems such as distributed filesystems or datastores. They work in conjunction with persistent volumes and provide for stable and unique network identifiers (FQDNs) as well as ordered deployments, scaling and deletion of the pods they're supervising.
Should you wish to learn more about StatefulSet
s, persistent data and stateful applications I'd encourage you to check out the following resources:
With that, I hope this post served you as a motivation for and introduction into the topic of state and storage with Kubernetes, and you can now appreciate a little bit better if and how Kubernetes can be used for stateful applications.
Categories
OpenShift Container Platform, How-tos, Products, OpenShift Dedicated, OpenShift Online
November 15, 2023
November 14, 2023
November 13, 2023