Cassandra is a popular distributed NoSQL open source database.

Using StorageOS persistent volumes with Cassandra means that if a Cassandra pod fails, the cluster is only in a degraded state for as long as it takes Kubernetes to restart the pod. When the pod comes back up the pod data is immediately available. Should Kubernetes schedule the Cassandra pod on a new node, StorageOS allows for the data to be available to the pod, irrespective of whether or not a StorageOS master is located on the same node.

As Cassandra has features to allow it to handle replication careful consideration of whether to allow StorageOS or Cassandra to handle replication is required.

Before you start, ensure you have StorageOS installed and ready on a Kubernetes cluster. See our guide on how to install StorageOS on Kubernetes for more information.

Deploying Cassandra on Kubernetes

  1. You can find the latest files in the StorageOS use cases repository

    git clone storageos-usecases

    StatefulSet defintion

    apiVersion: apps/v1
    kind: StatefulSet
     name: cassandra
         app: cassandra
     serviceName: cassandra
     replicas: 3
           - name: cassandra-data
             mountPath: /var/lib/cassandra
     - metadata:
         name: cassandra-data
         accessModes: ["ReadWriteOnce"]
         storageClassName: "fast" # StorageOS storageClass
             storage: 5Gi

    This excerpt is from the StatefulSet definition. This file contains the VolumeClaim template that will dynamically provision storage, using the StorageOS storage class. Dynamic provisioning occurs as a volumeMount has been declared with the same name as a VolumeClaimTemplate.

  2. Move into the Cassandra examples folder and create the objects

    cd storageos-usecases
    kubectl create -f ./cassandra
  3. Confirm Cassandra is up and running.

    $ kubectl get pods -w -l app=cassandra
    cassandra-0   1/1     Running   0          8m32s
    cassandra-1   1/1     Running   0          7m51s
    cassandra-2   1/1     Running   0          6m36s
  4. Connect to the Cassandra client pod and connect to the Cassandra server through the service

    $ kubectl exec -it cassandra-0 -- cqlsh cassandra-0.cassandra
    Connected to K8Demo at cassandra-0.cassandra:9042.
    [cqlsh 5.0.1 | Cassandra 3.11.3 | CQL spec 3.4.4 | Native protocol v4]
    Use HELP for help.
    cqlsh> SELECT cluster_name, listen_address FROM system.local;
     cluster_name | listen_address
           K8Demo |
    (1 rows)