
Apache Cassandra is a highly scalable, distributed NoSQL database designed to handle large volumes of data across multiple commodity servers. It's distributed architecture avoids single points of failure and enables horizontal scalability. Cassandra excels at write-heavy workloads and offers high write and read throughput, making it ideal for data-intensive applications. It also provides tunable consistency, accommodating varying data consistency needs.
K8ssandra is an open-source project that simplifies the deployment and management of Apache Cassandra on Kubernetes. It includes the K8ssandra Operator, which automates tasks such as cluster provisioning, scaling, backups, and repairs.
This article explains how to deploy a multi-node Apache Cassandra cluster on a Kubernetes Engine using the K8ssandra Operator.
Before you begin, you need to:
4 nodes and 4 GB RAM per node.cqlsh)The Cassandra CLI tool cqlsh is a Python-based command-line utility used to interact with Cassandra databases. Follow the steps below to install it.
Update the server package index.
Install Python and Pip.
View the installed Python version.
Your output should be similar to the one below:
View the installed Pip version.
Your output should be similar to the one below:
Create a python virtual environment.
Activate the python virtual environment.
Install the latest version of the cqlsh command-line interface:
View the installed cqlsh version.
Your output should be similar to the one below:
Cert-Manager is a Kubernetes operator that manages and issues TLS/SSL certificates within a cluster from trusted authorities such as Let's Encrypt. K8ssandra uses cert-manager to automate certificate management within a Cassandra clusters. This includes creating the Java key-stores and trust-stores needed from the certificates. Follow the steps in this section to install the cert-manager resources required by the K8ssandra Operator.
Using Helm, add the Cert-Manager Helm repository to your local repositories.
Update the local Helm charts index.
Install Cert-Manager to your VKE cluster.
When successful, verify that all Cert-Manager resources are available in the cluster.
Your output should be similar to the one below:
To manage Apache Cassandra clusters on Kubernetes, install the K8ssandra Operator using Helm. Follow the steps below to install the operator.
Add the K8ssandra operator repository to your Helm sources.
Install the K8ssandra operator in your cluster.
Wait a few minutes and view the cluster deployment to verify that the K8ssandra operator is available.
Your output should look like the one below:
Verify that the K8ssandra operator pods are ready and running.
Your output should look like the one below:
Use the K8ssandra Operator to deploy a highly available Cassandra cluster on Kubernetes Engine. Follow the steps below to set up Apache Cassandra Cluster.
Check available StorageClasses in your cluster.
Your output should look like the one below:
Using a text editor such as nano, create a new manifest file cluster.yaml.
Add the following contents to the file. Replace vultr-block-storage with the available StorageClass name in your cluster (as listed in the previous step).
Save and close the file.
The above manifest file defines the Cassandra cluster configuration with the following values:
4.0.1vultr-block-storage storage class with a 10 GB persistent volume per node.If you are deploying this on Vultr Kubernetes Engine (VKE), make sure to configure the Vultr CSI driver with your API key before deploying the cluster. This enables dynamic provisioning of block storage volumes. Refer to the Vultr CSI documentation for detailed setup instructions.
Apply the deployment to your cluster.
Wait for at least 15 minutes and view the cluster pods.
Verify that all pods are ready and running similar to the output below:
When all Cassandra database pods are ready, the Stargate Pod creation is initiated. Stargate provides a data gateway with REST, GraphQL, and Document APIs in front of the Cassandra database. The name of the Stargate Pod should be similar to: demo-dc1-default-stargate-deployment-xxxxxxxxx-xxxxx.
The K8ssandra operator deploys Apache Cassandra pods as StatefulSets to ensure stable network identities and persistent storage. Each StatefulSet manages a Cassandra node and is backed by a Persistent Volume Claim (PVC) for durable data storage. This section helps you verify that the PVCs are provisioned through Block Storage service for your Kubernetes Engine cluster.
Verify that the StatefulSet are available and ready in your cluster.
Your output should look like the one below:
This above output validates that all three Cassandra nodes are initialized and the StatefulSet is active.
Verify the available Storage class.
Your output should look like the one below:
List all Persistent Volume Claims (PVCs) across namespaces to confirm they are bound.
Your output should look like the one below:
To expose your Cassandra cluster externally and allow connections using the native Cassandra protocol (CQL) on port 9042, you must create a Kubernetes Service resource of type LoadBalancer. This will assign a public IP via Load Balancer integration.
Create a new service resource file service.yaml.
Add the following contents to the file.
Save and close the file.
The above configuration defines a Kubernetes service with a LoadBalancer type to access Cassandra cluster using port 9042.
Apply the service in the k8ssandra-operator namespace.
Wait for at least 5 minutes to deploy the cluster Loadbalancer resource and view the Cassandra service.
Verify the IP Address in your External-IP value to use for accessing the cluster.
If the EXTERNAL-IP field shows <pending>, wait a few more minutes and re-run the command. After an IP is assigned, use this IP to connect to Cassandra with a CQL client such as cqlsh.
cqlsh is a command-line interface that allows users to connect to the Cassandra cluster. Follow the steps in this section to execute CQL (Cassandra Query Language) statements, and perform various database operations, such as creating, modifying, and querying data.
Export your Cassandra service Load Balancer IP to the CASS_IP variable.
View the assigned Cassandra IP.
Export the cluster access username to the CASS_USERNAME variable.
View the Cassandra username.
Export the cluster the password to the CASS_PASSWORD variable.
View the Cassandra password.
Using cqlsh, log in to the Cassandra cluster using your variable values.
Create a new keyspace demo in the Cassandra database.
Create a new table users in the demo keyspace.
Insert records into the users table.
Query the table data to view the stored values.
Your output should be similar to the one below:
You have deployed an Apache Cassandra cluster on a Kubernetes Engine environment using the open-source K8ssandra operator. You configured persistent data storage with Block Storage and accessed the Cassandra cluster using the cqlsh CLI. For more information on advanced configuration and usage, refer to the official Cassandra documentation.
0 Comments
Be the first to comment and share your perspective with the community.