Trying CockroachDB¶
Prerequistites¶
Log into the cluster from the IBM Cloud shell as the cluster admin. Create a project in your OpenShift cluster where you want the operator to be installed.
oc new-project cockroachdb-trial
Try software¶
Let's see how the Free Trial
option works by selecting an SQL Operator. Go to the Marketplace catalog and search for CockroachDB
. Select the CockraochDB
tile. The CockraochDB
product page gives you an overview, documentation, and pricing options associated with the product selected. Click on Free Trail
button.
Next, the purchase summary will show the Subscription term
and total cost is $0.00. Click Start trial
. Go back to Workspace > My Software
to view the list of purchased software.
Operator install¶
Select the CockraochDB
tile and then select the Operators
tab. Click on Install Operator
button. Leave the default selection for Update channel
and Approval strategy
. Select the cluster and namespace scope as cockroachdb-trial
for the operator and click Install
.
In the list of installed cluster operators, a new row appears with the status Installing
.
Log into your OpenShift cluster and look under Operators > Installed Operators
to confirm the install was successful. The operator should list under the project cockroachdb-test
.
Create Database¶
From the installed Operators page for CockroachDB, click on the link CockroachDB
under Provided APIs.
Click on Create Cockroachdb
button. Accept the default YAML and click on Create
button. [Follow the instructions here to set up the database in a secure mode.]
CockroachDB pods should come up when the database install completes. Run the following commands to check the status.
$ oc project cockroachdb-test
Now using project "cockroachdb-test" on server "https://c100-e.us-east.containers.cloud.ibm.com:32345".
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
cockroachdb-7486949c78-kdvcm 1/1 Running 0 46m
example-cockroachdb-0 1/1 Running 0 36m
example-cockroachdb-1 1/1 Running 0 36m
example-cockroachdb-2 1/1 Running 0 36m
example-cockroachdb-init-l5m56 0/1 Completed 0 36m
Optional steps¶
Now, let's create a user and a database. We will use the following to command to spin up a CockroachDB client.
kubectl run -it --rm cockroach-client \
--image=cockroachdb/cockroach \
--restart=Never \
--command -- \
./cockroach sql --insecure --host=example-cockroachdb-public.cockroachdb-test
$ kubectl run -it --rm cockroach-client \
--image=cockroachdb/cockroach \
--restart=Never \
--command -- \
./cockroach sql --insecure --host=example-cockroachdb-public.cockroachdb-test
If you don't see a command prompt, try pressing enter.
root@example-cockroachdb-public.cockroachdb-test:26257/defaultdb>
From the client command prompt, run the following SQL commands:
Create user maxroach
CREATE USER IF NOT EXISTS maxroach;
root@example-cockroachdb-public.cockroachdb-test:26257/defaultdb> CREATE USER IF NOT EXISTS maxroach;
CREATE USER 1
Time: 13.604101ms
Create the database bank
CREATE DATABASE bank;
root@example-cockroachdb-public.cockroachdb-test:26257/defaultdb> CREATE DATABASE bank;
CREATE DATABASE
Time: 15.0454ms
Grant user the permission to update the database.
GRANT ALL ON DATABASE bank TO maxroach;
root@example-cockroachdb-public.cockroachdb-test:26257/defaultdb> GRANT ALL ON DATABASE bank TO maxroach;
GRANT
Time: 14.835156ms
Type \q
to quit the client console.
root@example-cockroachdb-public.cockroachdb-test:26257/defaultdb> \q
pod "cockroach-client" deleted
Access Database¶
Now, let's view the results of the commands we ran in the earlier steps via the admin console. Console can be accessed at localhost wwith port forwarding.
kubectl port-forward example-cockroachdb-0 8080
$ kubectl port-forward example-cockroachdb-0 8080
Forwarding from [::1]:8080 -> 8080
The page should load the cluster overview
Click on DATABASES
from the left navigation panel.
jdbc:postgresql://127.0.0.1:26257/bank?sslmode=disable example-cockroachdb-public.cockroachdb-test.svc.cluster.local
Conclusion¶
The CockroachDB instance is now ready for use.