ForkCoreWeaveCoreWeavepublished May 22, 2024seen 6d

coreweave/cockroach-operator

forked from cockroachdb/cockroach-operator

Open original ↗

Captured source

source ↗
published May 22, 2024seen 6dcaptured 9hhttp 200method plain

coreweave/cockroach-operator

Description: k8s operator for CRDB

Language: Go

License: Apache-2.0

Stars: 1

Forks: 0

Open issues: 1

Created: 2024-05-22T15:25:29Z

Pushed: 2024-09-05T15:07:36Z

Default branch: master

Fork: yes

Parent repository: cockroachdb/cockroach-operator

Archived: yes

README:

CockroachDB Kubernetes Operator

The CockroachDB Kubernetes Operator deploys CockroachDB on a Kubernetes cluster. You can use the Operator to manage the configuration of a running CockroachDB cluster, including:

  • Authenticating certificates
  • Configuring resource requests and limits
  • Scaling the cluster
  • Performing a rolling upgrade

Build Status

GKE Nightly: ![GKE Nightly](https://teamcity.cockroachdb.com/viewType.html?buildTypeId=Cockroach_CockroachOperator_Nightlies_GkeNightly)

OpenShift Nightly: ![OpenShift Nightly](https://teamcity.cockroachdb.com/viewType.html?buildTypeId=Cockroach_CockroachOperator_Nightlies_OpenShiftNightly)

Limitations

Prerequisites

  • Kubernetes 1.18 or higher
  • kubectl
  • A GKE cluster (n2-standard-4 is the minimum requirement for testing)

Install the Operator

Apply the custom resource definition (CRD) for the Operator:

kubectl apply -f https://raw.githubusercontent.com/cockroachdb/cockroach-operator/master/install/crds.yaml

Apply the Operator manifest. By default, the Operator is configured to install in the cockroach-operator-system namespace. To use the Operator in a custom namespace, download the Operator manifest and edit all instances of namespace: cockroach-operator-system to specify your custom namespace. Then apply this version of the manifest to the cluster with kubectl apply -f {local-file-path} instead of using the command below.

kubectl apply -f https://raw.githubusercontent.com/cockroachdb/cockroach-operator/master/install/operator.yaml

Validate that the Operator is running:

kubectl get pods
NAME READY STATUS RESTARTS AGE
cockroach-operator-6f7b86ffc4-9ppkv 1/1 Running 0 54s

Start CockroachDB

Download the `example.yaml` custom resource.

> Note: The latest stable CockroachDB release is specified by default in image.name.

Resource requests and limits

By default, the Operator allocates 2 CPUs and 8Gi memory to CockroachDB in the Kubernetes pods. These resources are appropriate for n2-standard-4 (GCP) and m5.xlarge (AWS) machines.

On a production deployment, you should modify the resources.requests object in the custom resource with values appropriate for your workload. For details, see the CockroachDB documentation.

Certificate signing

The Operator generates and approves 1 root and 1 node certificate for the cluster.

Apply the custom resource

Apply example.yaml:

kubectl create -f example.yaml

Check that the pods were created:

kubectl get pods
NAME READY STATUS RESTARTS AGE
cockroach-operator-6f7b86ffc4-9t9zb 1/1 Running 0 3m22s
cockroachdb-0 1/1 Running 0 2m31s
cockroachdb-1 1/1 Running 0 102s
cockroachdb-2 1/1 Running 0 46s

Each pod should have READY status soon after being created.

Access the SQL shell

To use the CockroachDB SQL client, first launch a secure pod running the cockroach binary.

kubectl create -f https://raw.githubusercontent.com/cockroachdb/cockroach-operator/master/examples/client-secure-operator.yaml

Get a shell into the client pod:

kubectl exec -it cockroachdb-client-secure -- ./cockroach sql --certs-dir=/cockroach/cockroach-certs --host=cockroachdb-public

If you want to [access the DB Console](#access-the-db-console), create a SQL user with a password while you're here:

CREATE USER roach WITH PASSWORD 'Q7gc8rEdS';

Then assign roach to the admin role to enable access to secure DB Console pages:

GRANT admin TO roach;
\q

Access the DB Console

To access the cluster's DB Console, port-forward from your local machine to the cockroachdb-public service:

kubectl port-forward service/cockroachdb-public 8080

Access the DB Console at https://localhost:8080.

Scale the CockroachDB cluster

> Note: Due to a known issue, automatic pruning of PVCs is currently disabled by default. This means that after decommissioning and removing a node, the Operator will not remove the persistent volume that was mounted to its pod. If you plan to eventually scale up the cluster after scaling down, you will need to manually delete any PVCs that were orphaned by node removal before scaling up. For more information, see the documentation.

To scale the cluster up and down, modify nodes in the custom resource. For details, see the CockroachDB documentation.

Do not scale down to fewer than 3 nodes. This is considered an anti-pattern on CockroachDB and will cause errors.

> Note: You must…

Excerpt shown — open the source for the full document.