Skip to content

Working with Data

Aleks Volochnev edited this page Mar 6, 2021 · 11 revisions

3. Working with Data

There are two main ways to communicate with Cassandra: API, and CQLSH. In this part, we will use both! Let's start with an application first:

✅ Step 1: Deploy the PetClinic app by applying the manifest.

kubectl apply -f petclinic.yaml

📃output

ec2-user@ip-172-31-5-5:~/kubernetes-workshop-online> kubectl apply -f petclinic.yaml
deployment.apps/petclinic-backend created                                                                                                   
service/petclinic-backend created                                                                                                           
deployment.apps/petclinic-frontend created                                                                                                  
service/petclinic-frontend created                                                                                                          
ingress.networking.k8s.io/petclinic-ingress created 

We can watch our app come online with the same command we used before. Just like last time use Ctrl + C to exit the watch.

watch kubectl get pods

📃output

Every 2.0s: kubectl get pods                                           ip-172-31-5-5.eu-central-1.compute.internal: Tue Nov 17 15:28:10 2020
                                                                                                                                            
NAME                                                              READY   STATUS      RESTARTS   AGE                                        
cass-operator-cd9b57568-hcqc6                                     1/1     Running     0          26m                                        
grafana-deployment-cfc94cf66-n7jk4                                1/1     Running     0          21m                                        
k8ssandra-cluster-a-grafana-operator-k8ssandra-6466cf94c9-skzrs   1/1     Running     0          23m                                        
k8ssandra-cluster-a-reaper-k8ssandra-59cb88b674-lh6cx             1/1     Running     0          20m                                        
k8ssandra-cluster-a-reaper-k8ssandra-schema-2p2tp                 0/1     Completed   4          23m                                        
k8ssandra-cluster-a-reaper-operator-k8ssandra-56cc9bf47c-9nt2l    1/1     Running     0          23m                                        
k8ssandra-dc1-default-sts-0                                       2/2     Running     0          23m                                        
k8ssandra-tools-kube-prome-operator-6d556b76f8-pqbmt              1/1     Running     0          26m                                        
petclinic-backend-7d47bcc6cc-smmv7                                1/1     Running     0          59s                                        
petclinic-frontend-75b98f7f8d-x2zgk                               1/1     Running     0          59s                                        
prometheus-k8ssandra-cluster-a-prometheus-k8ssandra-0             2/2     Running     1          23m                                        
traefik-7877ff76c9-rcm9n                                          1/1     Running     0          27m                                        

✅ Step 2: Using PetClinic

Navigate to the petclinic link in your cloud instance page to interact with the pet clinic app. If you have done everything correctly you should see the following.

images

If you are using your own infrastructure navigate to localhost:8080 to see the UI OK

Click on the pet types tab at the top of the page. OK

Click the add button and enter a new pet type. OK

To see the original app, the Pet Clinic app Github repo is here. But, we have forked our own version for today.

✅ Step 3: Retrieve K8ssandra superuser credentials.

You’ll need the K8ssandra superuser name and password in order to access Cassandra utilities and do things.

Retrieve the K8ssandra superuser name:

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

Output: k8ssandra-superuser

Retrieve the K8ssandra superuser password:

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

Output: PGo8kROUgAJOa8vhjQrE49Lgruw7s32HCPyVvcfVmmACW8oUhfoO9A

✅ Step 4: connect using CQLSH.

kubectl exec -it k8ssandra-dc1-default-sts-0 -c cassandra -- cqlsh -u k8ssandra-superuser -p <PASSWORD>

✅ Step 5: run basic CQL operations.

describe keyspaces;
use spring_petclinic;
describe tables;
select * from petclinic_pet_by_owner;

image

Next Step

Proceed to the Step IV