Jetstack are pleased to open source a proof-of-concept sidecar for deployment of managed Couchbase clusters on OpenShift. The project is the product of a close engineering collaboration with Couchbase, Red Hat and Amadeus, and a demo was presented at the recent Red Hat Summit in Boston, MA.
This project provides a sidecar container that can be used alongside official Couchbase images to provide a scalable and flexible Couchbase deployment for OpenShift and Kubernetes. The sidecars manage cluster lifecycle, including registering new nodes into the Couchbase cluster, automatically triggering cluster rebalances, and handling migration of data given a scale-down or node failure event.
Couchbase Server is a NoSQL document database with a distributed architecture for performance, scalability, and availability. It enables developers to build applications easier and faster by leveraging the power of SQL with the flexibility of JSON.
In recent versions of OpenShift (and the upstream Kubernetes project), there has seen significant advancement in a number of the building blocks required for deployment of distributed applications. Notably:
- StatefulSet: (nee PetSet, and now in technical preview as of OpenShift
3.5) provides unique and stable identity and storage to pods, and guarantees deployment order and scaling. This is in contrast to a Deployment or ReplicaSet where pod replicas do not maintain identity across restart/rescheduling, may have the same volume storage properties – hence, these resources are suited to stateless applications. - Dynamic volume provisioning: first introduced in technology preview in 3.1.1, and now GA in 3.3, this feature enables storage to be
dynamically provisioned ‘on-demand’ in a supported cloud environment (e.g. AWS, GCP, OpenStack). The StatefulSet controller automatically creates requests for storage (PersistentVolumeClaim – PVC) per pod, and the storage is provisioned (PersistentVolume – PV). The unique 1-to-1 binding between PV and PVC ensures a pod is always reunited with its same volume, even if scheduled on another node in the instance of failure.
Whilst OpenShift (or Kubernetes), by utilising its generic concepts of StatefulSet and dynamic volume provisioning, will make sure the right pods are scheduled and running, it cannot account for Couchbase-specific requirements in its decision making process. For example, registering new nodes when scaling up, rebalancing and also handling migration of data at a scale-down or on node failure. The pod and node events are well-known to OpenShift/Kubernetes, but the actions required are very much database-specific.
In this PoC, we’ve codified the main Couchbase cluster lifecycle operations into a sidecar container that sits alongside a standard Couchbase container in a pod. The sidecar uses the APIs of OpenShift/Kubernetes and Couchbase to determine cluster state, and it will safely and appropriately respond to Couchbase cluster events, such as scale-up/down and node failure.
For instance, the sidecar can respond to the following events:
- Scale-up: the sidecar determines the node is new to the cluster and it is initialized and joined to the cluster. This prompts a rebalance.
- Scale-down: a preStop hook (pre-container shutdown) is executed and the sidecar safely removes the node from the cluster, rebalancing as necessary.
- Readiness: the sidecar connects to the local Couchbase container and determines its health. The result of the readiness check is used to determine service availability in OpenShift.
Experiment with the open source sidecar
The proof-of-concept sidecar has now been open sourced at https://github.com/jetstack-experimental/couchbase-sidecar. At this repository, find instructions on how to get started with OpenShift (and Kubernetes too with a Helm chart). Feedback and contributions are welcome, but please note that this is strictly a proof-of-concept and should not be used in production. We look forward to future versions, in which the sidecar will be improved and extended, and battle-tested at scale, in a journey to a production release. Let us know what you think!