Skip to main content
Kubernetes is a portable, extensible platform for managing containerized workloads. You can deploy CockroachDB on Kubernetes using multiple approaches.

Deployment methods

CockroachDB Operator

Recommended for production. Automates cluster creation and management.

Helm Charts

Package manager for Kubernetes. Good for customizable deployments.

Manual StatefulSet

Maximum control with manual configuration files.
This guide focuses on the CockroachDB Operator method, which is recommended for most deployments.

Prerequisites

Kubernetes version

  • Kubernetes 1.30 or higher (for CockroachDB v25.1+)
  • Use a version with active patch support from the Kubernetes project

Resource requirements

  • Minimum per pod: 2 vCPUs and 8 GiB memory
  • Recommended for production: 4 vCPUs and 16 GiB memory
  • At least 3 nodes for a production cluster

Storage

  • Use local SSDs for best performance
  • Configure persistent volume provisioning
  • Avoid network-attached storage when possible

Network

  • PostgreSQL wire protocol is incompatible with SNI-based routing
  • Use a dedicated TCP load balancer for CockroachDB
  • Configure VPC peering for multi-region deployments

Start Kubernetes cluster

1

Install prerequisites

Install gcloud and kubectl:
# Follow Google Cloud SDK installation instructions
gcloud components install kubectl
2

Create cluster

gcloud container clusters create cockroachdb \
  --machine-type n2-standard-4 \
  --region us-east1 \
  --num-nodes 1
This creates a regional cluster with:
  • Machine type: n2-standard-4 (4 vCPUs, 16 GB memory)
  • One node per zone across 3 zones
3

Configure RBAC

Get your Google Cloud email:
gcloud info | grep Account
Create cluster role binding:
kubectl create clusterrolebinding $USER-cluster-admin-binding \
  --clusterrole=cluster-admin \
  [email protected]

Deploy CockroachDB with Operator

1

Clone Helm repository

git clone https://github.com/cockroachdb/helm-charts.git
2

Set environment variables

export CRDBOPERATOR=crdb-operator
export CRDBCLUSTER=cockroachdb
export NAMESPACE=cockroach-ns
3

Install the Operator

kubectl create namespace $NAMESPACE
helm install $CRDBOPERATOR ./cockroachdb-parent/charts/operator -n $NAMESPACE
4

Configure cluster values

Edit cockroachdb-parent/charts/cockroachdb/values.yaml:
cockroachdb:
  crdbCluster:
    regions:
      - code: us-central1
        nodes: 3
        cloudProvider: gcp
        namespace: cockroach-ns
cloudProvider: gcp
5

Configure resources

Set CPU and memory limits:
cockroachdb:
  crdbCluster:
    podTemplate:
      spec:
        resources:
          limits:
            cpu: 4000m
            memory: 16Gi
          requests:
            cpu: 4000m
            memory: 16Gi
6

Configure TLS certificates

Choose a certificate method:
cockroachdb:
  tls:
    enabled: true
Certificates are automatically generated.
7

Configure localities

Define locality mappings for replica distribution:
cockroachdb:
  crdbCluster:
    localityMappings:
      - nodeLabel: "topology.kubernetes.io/region"
        localityLabel: "region"
      - nodeLabel: "topology.kubernetes.io/zone"
        localityLabel: "zone"
For custom localities:
cockroachdb:
  crdbCluster:
    localityMappings:
      - nodeLabel: "topology.kubernetes.io/region"
        localityLabel: "region"
      - nodeLabel: "topology.kubernetes.io/zone"
        localityLabel: "zone"
      - nodeLabel: "example.datacenter.locality"
        localityLabel: "dc"
8

Install CockroachDB

helm install $CRDBCLUSTER ./cockroachdb-parent/charts/cockroachdb -n $NAMESPACE
Verify pods are running:
kubectl get pods -n $NAMESPACE
Expected output:
NAME                          READY   STATUS    RESTARTS   AGE
crdb-operator-655fbf7847-xxx  1/1     Running   0          10m
cockroachdb-0                 2/2     Running   0          45s
cockroachdb-1                 2/2     Running   0          45s
cockroachdb-2                 2/2     Running   0          45s

Access the cluster

Use SQL client

1

Create client pod

Download the client configuration:
curl -O https://raw.githubusercontent.com/cockroachdb/helm-charts/master/examples/client-secure.yaml
Edit the file and apply:
kubectl create -f client-secure.yaml
2

Connect to cluster

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

Run SQL commands

CREATE DATABASE bank;
CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);
INSERT INTO bank.accounts VALUES (1, 1000.50);
SELECT * FROM bank.accounts;

Access DB Console

1

Create admin user

CREATE USER roach WITH PASSWORD 'Q7gc8rEdS';
GRANT admin TO roach;
2

Port forward to service

kubectl port-forward service/cockroachdb-public 8080
3

Access console

Navigate to https://localhost:8080 and log in with your credentials.

Multi-region deployment

For multi-region clusters, configure multiple region definitions:
cockroachdb:
  clusterDomain: cluster.gke.gcp-us-east1
  crdbCluster:
    regions:
      - code: us-central1
        nodes: 3
        cloudProvider: gcp
        domain: cluster.gke.gcp-us-central1
        namespace: cockroach-ns
      - code: us-east1
        nodes: 3
        cloudProvider: gcp
        domain: cluster.gke.gcp-us-east1
        namespace: cockroach-ns
Multi-region deployments require:
  • VPC peering between regions
  • CoreDNS for cross-region service discovery
  • Single CA certificate across all regions
  • One operator deployment per region

Best practices

Storage

  • Use local SSDs instead of network-attached storage
  • Provision sufficient IOPS for your workload
  • Monitor disk usage regularly

Resources

  • Set resource requests equal to limits
  • Don’t use burstable or shared-core instances
  • Plan for 4 GiB RAM per vCPU

Topology

  • Spread pods across availability zones
  • Use topology spread constraints
  • Configure anti-affinity rules

Security

  • Always enable TLS for production
  • Rotate certificates before expiration
  • Use network policies to restrict access

Stop the cluster

To delete the cluster:
helm uninstall $CRDBCLUSTER -n $NAMESPACE
helm uninstall $CRDBOPERATOR -n $NAMESPACE
kubectl delete namespace $NAMESPACE
To delete the Kubernetes cluster:
gcloud container clusters delete cockroachdb --region us-east1
Deleting the Kubernetes cluster without removing persistent volumes will leave them in your cloud project.

Next steps

Build docs developers (and LLMs) love