Kubernetes: Stateful Apps with CockroachDB
This guide covers deploying a stateful application with CockroachDB using Kubernetes' StatefulSets feature. Topics include:
- An overview of options to deploy stateful applications
- Details about how StatefulSets and DaemonSets work in Kubernetes
- Steps to get your stateful application into production using CockroachDB
Want more details?
To get a better sense of what's in the guide, check out its introduction below:
Over the past year, Kubernetes––also known as K8s––has become a dominant topic of conversation in the infrastructure world. Given that it’s patterned after Google’s own infrastructure needs, it makes sense that people want to bring that kind of power to their own DevOps stories. Container orchestration turns many tedious and complex tasks into something as simple as a declarative config file.
The rise of orchestration is predicated on a few things, though. First, organizations have moved toward breaking up monolithic applications into microservices. However, the resulting environments have hundreds (or thousands) of these services that need to be managed and orchestration makes that Herculean task feasible. Second, infrastructure has become cheap and disposable––if a machine fails, it’s dramatically cheaper to replace it than triage the problems.
So, to solve the first issue, orchestration relies on the boon of the second; it manages services by simply letting new machines (running the exact same containers) take the place of failed ones, which keeps a service running without any manual interference.
The software most amenable to being orchestrated are ones that can easily spin up new interchangeable instances without requiring coordination across zones.
For most databases, this is a challenging task. However, because of CockroachDB's cloud-native design, it thrives in an orchestrated environment.
How CockroachDB Works on Kubernetes
CockroachDB’s origin story has a major parallel to Kubernetes’: both have their roots in Google’s infrastructure. While CockroachDB is modeled after Google’s scalable and consistent database, Spanner, Kubernetes is a simplified clone of Google’s orchestration system, Borg. This shared ideological DNA makes it natural that the two would work well together.
Kubernetes’ StatefulSets feature was a huge step forward toward simplifying support for stateful services. Using it, database pods that are rescheduled to other nodes are able to “keep” the same remote disk and simply re-attach to it on its new Kubernetes node.
CockroachDB was designed to be a highly-available, fault-tolerant database meant to withstand chaotic deployments, which is powered by the Multi-Active Availability model. This feature lets us accept reads and writes on any CockroachDB node without sacrificing serializable isolation. Through multi-active availability, CockroachDB handles rescheduling gracefully. Moving between Kubernetes nodes is no different from a temporary node outage, which CockroachDB is well equipped to handle.
Want to read more? Get the guide.