Apache Cassandra Deployment on OpenEBS and Monitoring on Kubera

Apache Cassandra is a distributed NoSQL database management system designed to handle large amounts of data across nodes, providing high availability with no single point of failure. It uses asynchronous masterless replication allowing low latency operations for all clients. Cassandra is usually deployed as a stateful on Kubernetes and requires persistent storage for each instance of Cassandra. OpenEBS provides persistent volumes on the fly when Cassandra instances are scaled up.

Apache Cassandra Deployment on OpenEBS:

Cassandra NoSQL distributed database with OpenEBS

Step 1: Install OpenEBS
If OpenEBS is not installed in your K8s cluster, this can be done from here. If OpenEBS is already installed, go to the next step.

Step 2: Configure cStor Pool
After OpenEBS installation, the cStor pool has to be configured. If cStor Pool is not configured in your OpenEBS cluster, this can be done from here. During cStor Pool creation, make sure that the maxPools parameter is set to >=3. Sample YAML named openebs-config.yaml for configuring cStor Pool is provided below. If the cStor pool is already configured, go to the next step.

#Use the following YAMLs to create a cStor Storage Pool.
# and associated storage class.
apiVersion: openebs.io/v1alpha1
kind: StoragePoolClaim
  name: cstor-disk
  name: cstor-disk
  type: disk
    poolType: striped
 # NOTE - Appropriate disks need to be fetched using `kubectl get blockdevices -n openebs`
  # `Block devices` is a custom resource supported by OpenEBS with `node-disk-manager`
  # as the disk operator
# Replace the following with actual disk CRs from your cluster `kubectl get blockdevices -n openebs`
# Uncomment the below lines after updating the actual disk names.
# Replace the following with actual disk CRs from your cluster from `kubectl get blockdevices -n openebs`
#   - blockdevice-69cdfd958dcce3025ed1ff02b936d9b4
#   - blockdevice-891ad1b581591ae6b54a36b5526550a2
#   - blockdevice-ceaab442d802ca6aae20c36d20859a0b

Step 3: Create Storage Class
You must configure a StorageClass to provision cStor volume on a given cStor pool. StorageClass is the interface through which most of the OpenEBS storage policies are defined. In this solution, we are using a StorageClass to consume the cStor Pool, which is created using external disks attached to the Nodes. Since Cassandra is a StatefulSet application, it requires only one replication at the storage level. So the cStor volume replicaCount is 1. Sample YAML named openebs-sc-disk.yaml to consume cStor pool with cStor volume replica count as 1 is provided below.

apiVersion: storage.k8s.io/v1
kind: StorageClass
  name: openebs-cstor-disk
    openebs.io/cas-type: cstor
    cas.openebs.io/config: |
      - name: StoragePoolClaim
        value: "cstor-disk"
      - name: ReplicaCount
        value: "1"
provisioner: openebs.io/provisioner-iscsi
reclaimPolicy: Delete

Step 4: Launch Cassandra
Create a sample cassandra-statefulset.yaml file in the Configuration details section. This can be applied to deploy the Cassandra database with OpenEBS. Run kubectl apply -f cassandra-statefulset.yaml to see Cassandra running. This will configure the required PVC also.

apiVersion: apps/v1beta1
kind: StatefulSet
  name: cassandra
    app: cassandra
  serviceName: cassandra
  replicas: 3
      app: cassandra
        app: cassandra
      - name: cassandra
        image: gcr.io/google-samples/cassandra:v11
        imagePullPolicy: Always
        - containerPort: 7000
          name: intra-node
        - containerPort: 7001
          name: tls-intra-node
        - containerPort: 7199
          name: jmx
        - containerPort: 9042
          name: cql
            cpu: "500m"
            memory: 1Gi
           cpu: "500m"
           memory: 1Gi
              - IPC_LOCK
              command: ["/bin/sh", "-c", "PID=$(pidof java) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"]
          - name: MAX_HEAP_SIZE
            value: 512M
          - name: HEAP_NEWSIZE
            value: 100M
          - name: CASSANDRA_SEEDS
            value: "cassandra-0.cassandra.default.svc.cluster.local"
          - name: CASSANDRA_CLUSTER_NAME
            value: "K8Demo"
          - name: CASSANDRA_DC
            value: "DC1-K8Demo"
          - name: CASSANDRA_RACK
            value: "Rack1-K8Demo"
            value: "false"
          - name: POD_IP
                fieldPath: status.podIP
            - /bin/bash
            - -c
            - /ready-probe.sh
          initialDelaySeconds: 15
          timeoutSeconds: 5
        # These volume mounts are persistent. They are like inline claims,
        # but not exactly because the names need to match exactly one of
        # the stateful pod volumes.
        - name: cassandra-data
          mountPath: /cassandra_data
  - metadata:
      name: cassandra-data
        volume.beta.kubernetes.io/storage-class: openebs-cstor-disk
      accessModes: [ "ReadWriteOnce" ]
          storage: 5G


Apache Cassandra Monitoring on Kubera:

Connect your cluster to Kubera on which the Cassandra application is deployed. To know more, click here.

Step 1:
After connecting your cluster to Kubera, go to Cluster-->Applications-->Cassandra-->Analytics.

You will get a dashboard to enable analytics. Click on Enable Analytics.

Fig 1: Apache Cassandra Deployment on OpenEBS and Monitoring on Kubera

Step 2:

Clicking on Enable Analytics gives us the option of enabling the Automate Exporter. To enable the Automate-Exporter, click on the Enable option, as shown in the image.

Fig 2: Apache Cassandra Deployment on OpenEBS and Monitoring on Kubera

Step 3:
Clicking on Enable will redirect us to the Cassandra Application Dashboard.

Fig 3: Apache Cassandra Deployment on OpenEBS and Monitoring on Kubera

Step 4:
Clicking on View More present at the bottom to get the detailed overview and statistics of the application, as shown in the image below.

Fig 4: Apache Cassandra Deployment on OpenEBS and Monitoring on Kubera
Paul Burt
Prior to working with MayaData, Paul has worked with NetApp & Red Hat in senior positions. He’s upvoting your /r/kubernetes threads. Paul has a knack for and demystifying infrastructure, and making gnarly, complex topics approachable. He enjoys home brewing beer, reading independent comics, and yelling at his computer when it doesn’t do what he wants.
Abhishek Raj
Abhishek is a Customer Success Engineer at Mayadata. He is currently working with Kubernetes and Docker.
Niladri is a CSAT Solutions / Support Engineer at MayaData. He works with Kubernetes, Docker, and the rest of the stack down below.