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:
- State is a temporal property of a process. Stateless means that a process does not keep track of past interactions, essentially one can say it's a purely functional behavior. Stateful, on the other hand, means that the process has a record of previous interactions and can respond, based on it. Where the state is kept, that is, in main memory or persisted on disk, is a different question.
- Storage, meaning a persistent way to keep data around, nowadays typically on a hard disk drive or an SSD. In case a process operates purely on data in main memory, there's no disk I/O. If disk I/O is carried out, it might be read-only or in a read-write manner.
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:
- Stateful applications with read-write disk access (quadrant A) such as a service carrying out a financial transaction backed by an RDBMS.
- Stateless applications with read-write disk access (quadrant B), for example, an idempotent file upload service.
- Stateless applications with read-only disk access such as a web server that (on start-up) reads the static content it serves from an external storage, for example from S3.
- Stateless applications without disk access (quadrant C), such as a converter services for geo coordinates.
- Stateful applications without disk access (quadrant D), like a shopping basket service in an eCommerce site.
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:
- Tutorial on StatefulSets Basics via Kubernetes docs.
- Blog post StatefulSet: Run and Scale Stateful Applications Easily in Kubernetes via Kubernetes blog.
- Blog post Deploying PostgreSQL Clusters using StatefulSets via Kubernetes blog.
- Blog post How I deployed GlusterFS to Kubernetes by Sergey Nuzhdin.
- Blog post Kubernetes persistent storage with Ceph by Alen Komljen.
- Blog post Stateful containerized applications with Kubernetes by Josh Berkus.
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.
Sobre el autor
Navegar por canal
Automatización
Las últimas novedades en la automatización de la TI para los equipos, la tecnología y los entornos
Inteligencia artificial
Descubra las actualizaciones en las plataformas que permiten a los clientes ejecutar cargas de trabajo de inteligecia artificial en cualquier lugar
Nube híbrida abierta
Vea como construimos un futuro flexible con la nube híbrida
Seguridad
Vea las últimas novedades sobre cómo reducimos los riesgos en entornos y tecnologías
Edge computing
Conozca las actualizaciones en las plataformas que simplifican las operaciones en el edge
Infraestructura
Vea las últimas novedades sobre la plataforma Linux empresarial líder en el mundo
Aplicaciones
Conozca nuestras soluciones para abordar los desafíos más complejos de las aplicaciones
Programas originales
Vea historias divertidas de creadores y líderes en tecnología empresarial
Productos
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Servicios de nube
- Ver todos los productos
Herramientas
- Training y Certificación
- Mi cuenta
- Soporte al cliente
- Recursos para desarrolladores
- Busque un partner
- Red Hat Ecosystem Catalog
- Calculador de valor Red Hat
- Documentación
Realice pruebas, compras y ventas
Comunicarse
- Comuníquese con la oficina de ventas
- Comuníquese con el servicio al cliente
- Comuníquese con Red Hat Training
- Redes sociales
Acerca de Red Hat
Somos el proveedor líder a nivel mundial de soluciones empresariales de código abierto, incluyendo Linux, cloud, contenedores y Kubernetes. Ofrecemos soluciones reforzadas, las cuales permiten que las empresas trabajen en distintas plataformas y entornos con facilidad, desde el centro de datos principal hasta el extremo de la red.
Seleccionar idioma
Red Hat legal and privacy links
- Acerca de Red Hat
- Oportunidades de empleo
- Eventos
- Sedes
- Póngase en contacto con Red Hat
- Blog de Red Hat
- Diversidad, igualdad e inclusión
- Cool Stuff Store
- Red Hat Summit