HOW TO: Access Cassandra & Create Cassandra Users

To get the cassanrda super user credentials for your basic demo cluster execute the following commands:

kubectl get secret k8ssandra-superuser -o jsonpath="{.data.username}" | base64 --decode ; echo
kubectl get secret k8ssandra-superuser -o jsonpath="{.data.password}" | base64 --decode ; echo

To access cassandra cqlsh exec on a cassandra pod:

kubectl exec -it k8ssandra-dc1-default-sts-0 /bin/bash

cassandra@k8ssandra-dc1-default-sts-0:/$ cqlsh localhost 9042 -u k8ssandra-superuser -p OydXi6iO4MEUUqODGAC3

Some examples to create additional roles other than super user, from cqlsh:

CREATE ROLE new_role;
CREATE ROLE alice WITH PASSWORD = 'password_a' AND LOGIN = true;
CREATE ROLE bob WITH PASSWORD = 'password_b' AND LOGIN = true AND SUPERUSER = true;
CREATE ROLE carlos WITH OPTIONS = { 'custom_option1' : 'option1_value', 'custom_option2' : 99 };
CREATE ROLE alice WITH PASSWORD = 'password_a' AND LOGIN = true AND ACCESS TO DATACENTERS {'DC1', 'DC3'};
CREATE ROLE alice WITH PASSWORD = 'password_a' AND LOGIN = true AND ACCESS TO ALL DATACENTERS;

reference: Documentation

1 Like

@DsMatison Hi Steve,
I am having a different use case where i have to connect kafka with k8ssandra. I am able to do it successfully but the issue is my username and password is visible in the configuration.
Is there any way i can connect to cqlsh k8ssandra without providing username and password. instead of credential , i can provide kubernetes secret.?

1 Like

Yes, check out this source code to pass the secret to a deployment yaml as Environment variables:

          - name: K8S_USERNAME
            valueFrom:
              secretKeyRef:
                name: k8ssandra-superuser 
                key: username
          - name: K8S_PASSWORD
            valueFrom: 
              secretKeyRef:
                name: k8ssandra-superuser 
                key: password              

You can find a full sample at: GitHub - ds-steven-matison/k8ssandra-docker: How to deploy a docker app in k8ssandra.

@DsMatison Steve i am using helm chart of k8ssandra to deploy it on my kubernetes cluster.
can you please let me know where i can make the necessary changes in the charts

Hi @Shubham_Srivastava

Take a look at these:

Cheers

John

1 Like

Hi k8 cassandra Team,

I am trying to enable istio side car injection in k8ssandra. proxy container is getting injected in one pod of k8ssandra. i.e cassandra-cass-operator-d8c449c9-pqhnb but not getting injected in second pod cassandra-dc1-default-sts-0 .
proxy container in second pod is failing the health check. Can any one support me in solving this issue