Deploying an Open Source Apache Cassandra Database using the GCP Marketplace
Vignesh Sivakumar
Cloud Architect | Transforming Businesses with Cloud-Native Solutions | GCP Expert | Migration, Automation, DevOps, MLOps & GenAI
Objectives
- Deploy Apache Cassandra using the GCP marketplace
- Connect to Apache Cassandra using CQL
- Create keyspaces and tables using CQL
- Insert and Query data using CQL
- Destroy Apache Cassandra
Prerequisites
- Google Cloud Platform Account
- A Project with billing enabled
Google Products
- Google Cloud Marketplace
- Compute Engine
- Cloud Deployment Manager
- Cloud Shell
Deploy Apache Cassandra using the GCP marketplace
1. Open Google Console https://console.cloud.google.com/
2. On the left side of browse on the Navigation Menu and click on the Marketplace https://console.cloud.google.com/marketplace
3. Search for “Cassandra Certified by Bitnami†and click on the result Cassandra Certified by Bitnami.
4. Click on the LAUNCH button.
It may take a few minutes to configure APIs and launch.
5. Give the name for the deployment in Deployment Name and select Zone where you want to deploy the application. Choose the Machine type, Boot disk size, and Networking based on the need. Select the Checkbox for accepting the GCP Marketplace Terms of Service. And Click on the Deploy button.
When you click on the deploy button you will be redirected to the Deployment Manager Page. It may take a few minutes. Once deployed you will see a Green Checkbox with your deployment name. Ex. cassandra-1 has been deployed
Connect to Apache Cassandra using CQL
1. Note the Admin user and Admin password on the right-hand side.
2. To connect to the database, click on the drop-down menu in the SSH button and select Open in browser window.
3. Type the below comment with the username and password you have copied on Step 1 to connect to the instance.
cqlsh -u <username> -p <password>
Ex: cqlsh -u cassandra -p tMXGUr2piqcr
Create a keyspace and table using CQL
1. After login into the Cassandra database, create a keyspace using the below command.
CREATE KEYSPACE thecloudnuggets WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1};
You can set the replication factor bases on your need. The replication option is to specify the Replica Placement Strategy and the number of replicas wanted.
2. Create a table in the keyspace using the below command.
CREATE TABLE thecloudnuggets.nuggets ( nuggets_id int PRIMARY KEY, nuggets_name text, nuggets_city text, nuggets_sal varint, nuggets_phone varint );
You can view the created Keyspace using the below command.
DESCRIBE KEYSPACE thecloudnuggets;
Insert and Query data using CQL
1. Insert Sample Data into the created table using the following command.
INSERT INTO <tablename> (<column1 name>, <column2 name>....) VALUES (<value1>, <value2>....)
Example:
INSERT INTO thecloudnuggets.nuggets ( nuggets_id, nuggets_name, nuggets_city, nuggets_phone, nuggets_sal) VALUES(1,'The', 'TN', 9848022338, 50000); INSERT INTO thecloudnuggets.nuggets ( nuggets_id, nuggets_name, nuggets_city, nuggets_phone, nuggets_sal) VALUES(2,'Cloud', 'TN', 9848022338, 50000);
INSERT INTO thecloudnuggets.nuggets ( nuggets_id, nuggets_name, nuggets_city, nuggets_phone, nuggets_sal) VALUES(3,'Nuggets', 'TN', 9848022338, 50000);
2. Query the table to view the data from the created table.
select * from thecloudnuggets.nuggets;
3. Exit the CQL shell using the below command
cqlsh> exit
Destroy Apache Cassandra
1. On the left side of browse on the Navigation Menu and click on the Deployment Manager under the Tools section.
2. Select the checkbox of your deployment name and click Delete on the top.
After Clicking on the Delete button you will get a pop in that select Delete and all resources created by it,... and Click DELETE ALL. This will completely destroy the environment you created above.
Congratulations!
In this article, we deployed an Apache Cassandra database, connected to the database using CQL Shell, and run some simple DDL commands to create a table, load some data, and query it. Finally, we destroyed the environment that created.