Quickstart for developers
Tip
Before performing these post-install steps, complete at least one K8ssandra Operator cluster deployment in Kubernetes.In this quickstart for developers, we’ll cover:
- Setting up port forwarding to access CQLSH outside your Kubernetes (K8s) cluster.
- Accessing Cassandra using CQLSH including some basic CQL commands.
Set up port forwarding
In order to access Apache Cassandra® outside of the K8s cluster, you’ll need to utilize port forwarding. Begin by getting a list of your K8ssandra K8s services and ports:
kubectl get services
Use the Cassandra client service, demo-dc1-service, on port 9042.
To configure port forwarding:
-
Open a new terminal.
-
Run the
kubectl port-forwardcommand in the background:kubectl port-forward svc/demo-dc1-service 9042 &Output:
[1] 80940 Forwarding from 127.0.0.1:9042 -> 9042 Forwarding from [::1]:9042 -> 9042
Terminate port forwarding
To terminate the port forwarding service:
-
Get the process ID:
jobs -lOutput:
[1] + 80940 running kubectl port-forward svc/demo-dc1-service 9042 -
Kill the process
kill 80940Output:
[1] + terminated kubectl port-forward svc/demo-dc1-service 9042
Tip
Exiting the terminal instance will terminate the port forwarding service.Access Cassandra using CQLSH
If you’re familiar with Cassandra, then you’re familiar with CQLSH. You can download a full-featured stand alone CQLSH utility from Datastax and use that to interact with K8ssandra as if you were in a native Cassandra environment.
To access K8ssandra using the stand alone CQLSH utility:
-
Make sure you have Python 2.7 installed on your system.
-
Download CQLSH from the DataStax download site choosing the version for DataStax Astra.
-
Connect to Cassandra replacing
<k8ssandra-username>and<k8ssandra-password>with the values you retrieved in Retrieve K8ssandra superuser credentials:cqlsh -u <k8ssandra-username> -p <k8ssandra-password>Output:
Connected to k8ssandra at 127.0.0.1:9042. [cqlsh 6.8.0 | Cassandra 3.11.6 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. k8ssandra-superuser@cqlsh> -
Create a new keyspace,
k8ssandra_test, using CREATE KEYSPACE:CREATE KEYSPACE k8ssandra_test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}; -
Switch to the new keyspace using USE:
USE k8ssandra_test; -
Create a new table,
usersusing CREATE TABLECREATE TABLE users (email text primary key, name text, state text); -
Insert some sample data into the new table using INSERT
INSERT INTO users (email, name, state) values ('[email protected]', 'Alice Smith', 'TX'); INSERT INTO users (email, name, state) values ('[email protected]', 'Bob Jones', 'VA'); INSERT INTO users (email, name, state) values ('[email protected]', 'Carol Jackson', 'CA'); INSERT INTO users (email, name, state) values ('[email protected]', 'David Yang', 'NV'); -
Query the data using SELECT and validate the return results:
SELECT * FROM k8ssandra_test.users;Output:
email | name | state -------------------+---------------+------- alice@example.com | Alice Smith | TX bob@example.com | Bob Jones | VA david@example.com | David Yang | NV carol@example.com | Carol Jackson | CA (4 rows) -
When you’re done, exit CQLSH using
QUIT:cqlsh> QUIT;
For complete details on Cassandra, CQL and CQLSH, see the Apache Cassandra web site.
Next steps
- Components: Dig in to each deployed component of the K8ssandra stack and see how it communicates with the others.
- Tasks: Need to get something done? Check out the Tasks topics for a helpful collection of outcome-based solutions.
- Reference: Explore the Custom Resource Definitions (CRDs) used by K8ssandra Operator.
We encourage developers to actively participate in the K8ssandra community.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.