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 StatefulSets, 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.
저자 소개
유사한 검색 결과
Key considerations for 2026 planning: Insights from IDC
Red Hat and Sylva unify the future for telco cloud
Edge computing covered and diced | Technically Speaking
SREs on a plane | Technically Speaking
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래