
CockroachDB is a distributed SQL database system designed to support data-intensive applications in production environments by replicating data to multiple nodes within a cluster. In case a single cluster node fails, CockroachDB elects new nodes with high availability and enhanced scaling to balance the database load. In addition, the Cockroach DB automated repair feature detects data inconsistencies and automatically corrects any corrupted databases to keep the cluster applications running.
This guide explains how to deploy CockroachDB on a Vultr Kubernetes Engine (VKE) cluster to enable scalability, fault tolerance, and management using the cluster SQL client or graphical interface.
Before you begin:
3 nodes, 8 GB RAM and 4 VcPUs in a supported Vultr Block Storage location.A CockroachDB Kubernetes operator manages the deployment process with the automation of tasks such as scaling and maintenance of Cockroach DB instances on each node within the cluster. Follow the steps below to install the CockroachDB operator and necessary dependencies in a new cockroach-operator-system namespace to run a CockroachDB cluster.
Install the latest Cockroach DB Operator Custom Resource Definitions (CRDs).
The above command installs the CockroachDB Operator CRDs version v2.12.0. Visit the operator tags page to verify the latest version.
Install the CockroachDB Operator.
Output:
Wait for at least 2 minutes for the deployment process to complete. Then, view all pods in the CockroachDB Operator namespace cockroach-operator-system.
Verify that all pods are ready and running similar to the output below:
To create a CockroachDB cluster, specify the necessary storage volumes, CPU count, and memory limits to use with the database nodes. In a production environment, define a PVC resource to use Vultr Block Storage volumes with at least 60 GB storage, 2 vCPUs, and 8 GB memory. Follow the steps below to deploy a CockroachDB cluster with the minimum production values.
Create a new directory cockroadbdb-cluster to store the cluster manifest files.
Change to the directory.
Create a new CoackroachDB cluster resource file cluster.yaml to define the operator functions.
Add the following contents to the file.
Save and close the file.
The above cluster configuration creates a CockroachDB cluster with 60 GB storage per Vultr Block Storage volume, and a limit of 2 vCPUs, 8 GiB memory for each database node within the cluster.
Apply the configuration to create the CockroachDB cluster.
Output:
Wait at least 3 minutes for the CoackroachDB cluster and Vultr Block Storage volumes creation process to complete. Then, view the CockroachDB cluster resource to verify its run-time status.
Output:
View the cluster Pods to verify that all CockroachDB resources are ready and running.
Your output should look like the one below:
CockroachDB is accessible within the cluster using the internal cockroachdb-public service address. To externally access the cluster, create a new internal cockroach binary pod to use the SQL client, and set up a new load balancer resource to access the graphical database console as described in the steps below.
List all cluster services to verify the available CockroachDB resources.
Your output should look like the one below:
As displayed in the output above, pods within the same namespace communicate to CockroachDB resources using the cockroachdb-public service internal cluster IP address.
Create a new cockroachdb binary pod to access the CockroachDB SQL client.
View the cluster pods to verify that the cockroachdb-client-secure SQL client is ready and running.
Output:
Access the pod shell using the cockroachdb-public service as the host gateway to access CockroachDB.
Output:
Create a sample CockroachDB database.
Output:
Create a new CockroachDB database user with a strong password.
Output:
Grant administrative database privileges to the user.
Exit the pod shell.
Create a new load balancer resource using the cockroachdb-public service to expose the CockroachDB graphical console with an external IP Address.
Wait for at least 3 minutes to attach a Vultr LoadBalancer to the service. Then, view the cluster services to verify the assigned public IP Address.
Your output should look like the one below:
Access the CockroachDB port 8080 using your external service IP Address in a new web browser session. Replace 192.168.0.34 with your actual load balancer IP address.
Log in to the database console using the example_admin user and password you created earlier in the SQL client.
Verify the CockroachDB cluster status, nodes, and databases in the graphical management console to integrate other cluster applications.
You have installed CockroachDB on a Vultr Kubernetes Engine (VKE) cluster and accessed the database using a graphical management console. Depending on your cluster applications, you can integrate internal and external applications to the database with automatic failover capabilities to ensure high application availability in case a cluster node fails. For more information about CockroachDB, visit the official documentation.
0 Comments
Be the first to comment and share your perspective with the community.