To orchestrate a physically distributed cluster in production, see . To deploy a 30-day free CockroachDB Advanced cluster instead of running CockroachDB yourself, see the .
Best practices
Kubernetes version
To deploy CockroachDB v25.3, Kubernetes 1.18 or higher is required. Cockroach Labs strongly recommends that you use a Kubernetes version that is eligible for patch support by the Kubernetes project.Public operator
- The Public operator deploys clusters in a single region. For multi-region deployments using manual configs, Cockroach Labs recommends using the which is designed to support multi-region deployments. For guidance on how to force multi-region support with the Public operator, see .
- Using the Public operator, you can give a new cluster an arbitrary number of labels. However, a cluster’s labels cannot be modified after it is deployed. To track the status of this limitation, refer to #993 in the Public operator project’s issue tracker.
Helm version
The CockroachDB Helm chart requires Helm 3.0 or higher. If you attempt to use an incompatible Helm version, an error like the following occurs:Network
Service Name Indication (SNI) is an extension to the TLS protocol which allows a client to indicate which hostname it is attempting to connect to at the start of the TCP handshake process. The server can present multiple certificates on the same IP address and TCP port number, and one server can serve multiple secure websites or API services even if they use different certificates. Due to its order of operations, the PostgreSQL wire protocol’s implementation of TLS is not compatible with SNI-based routing in the Kubernetes ingress controller. Instead, use a TCP load balancer for CockroachDB that is not shared with other services.Resources
When starting Kubernetes, select machines with at least 4 vCPUs and 16 GiB of memory, and provision at least 2 vCPUs and 8 Gi of memory to CockroachDB per pod. These minimum settings are used by default in this deployment guide, and are appropriate for testing purposes only. On a production deployment, you should adjust the resource settings for your workload. For details, see .Storage
Kubernetes deployments use external persistent volumes that are often replicated by the provider. CockroachDB replicates data automatically, and this redundant layer of replication can impact performance. Using local volumes may improve performance.Before you begin
Before getting started, it’s helpful to review some Kubernetes-specific terminology:Step 1. Start Kubernetes
-
Follow the Minikube documentation to install the latest version of
minikube, a hypervisor, and thekubectlcommand-line tool. -
Start a local Kubernetes cluster:
Step 2. Start CockroachDB
To start your CockroachDB cluster, you can either use our StatefulSet configuration and related files directly, or you can use the Helm package manager for Kubernetes to simplify the process.-
From your local workstation, use our file to create the StatefulSet that automatically creates 3 pods, each with a CockroachDB node running inside it:
-
Confirm that three pods are
Runningsuccessfully. Note that they will not be consideredReadyuntil after the cluster has been initialized: -
Confirm that the persistent volumes and corresponding claims were created successfully for all three pods:
-
Use our file to perform a one-time initialization that joins the CockroachDB nodes into a single cluster:
-
Confirm that cluster initialization has completed successfully. The job should be considered successful and the Kubernetes pods should soon be considered
Ready:
-
Install the Helm client (version 3.0 or higher) and add the
cockroachdbchart repository: -
Update your Helm chart repositories to ensure that you’re using the latest CockroachDB chart:
- The cluster configuration is set in the Helm chart’s values file.
By default, the Helm chart specifies CPU and memory resources that are appropriate for the virtual machines used in this deployment example. On a production cluster, you should substitute values that are appropriate for your machines and workload. For details on configuring your deployment, see .
-
Create a local YAML file (e.g.,
my-values.yaml) to specify your custom values. These will be used to override the defaults invalues.yaml. -
To avoid running out of memory when CockroachDB is not the only pod on a Kubernetes node, you must set memory limits explicitly. This is because CockroachDB does not detect the amount of memory allocated to its pod when run in Kubernetes. We recommend setting
conf.cacheandconf.max-sql-memoryeach to 1/4 of thememoryallocation specified instatefulset.resources.requestsandstatefulset.resources.limits.
tls.enabled to true. For an insecure deployment, set tls.enabled to false:
values.yaml template.
-
Install the CockroachDB Helm chart, specifying your custom values file.
Provide a “release” name to identify and track this particular deployment of the chart, and override the default values with those in
my-values.yaml.
This tutorial uses
my-release as the release name. If you use a different value, be sure to adjust the release name in subsequent commands.To allow the CockroachDB pods to successfully deploy, do not set the
--wait flag when using Helm commands.-
Install the CockroachDB Helm chart.
Provide a “release” name to identify and track this particular deployment of the chart.
This tutorial uses
my-releaseas the release name. If you use a different value, be sure to adjust the release name in subsequent commands.Behind the scenes, this command uses ourcockroachdb-statefulset.yamlfile to create the StatefulSet that automatically creates 3 pods, each with a CockroachDB node running inside it, where each pod has distinguishable network identity and always binds back to the same persistent storage on restart. -
Confirm that CockroachDB cluster initialization has completed successfully, with the pods for CockroachDB showing
1/1underREADYand the pod for initialization showingCOMPLETEDunderSTATUS: -
Confirm that the persistent volumes and corresponding claims were created successfully for all three pods:
stderr, so if you ever need access to a pod/node’s logs to troubleshoot, use kubectl logs <podname> rather than checking the log on the persistent volume.
Step 3. Use the built-in SQL client
-
Launch a temporary interactive pod and start the inside it:
-
Run some basic :
-
Exit the SQL shell and delete the temporary pod:
Step 4. Access the DB Console
To access the cluster’s :-
On secure clusters, can only be accessed by
adminusers. Get a shell into the pod and start the CockroachDB :$ kubectl exec -it cockroachdb-client-secure
— ./cockroach sql
—certs-dir=/cockroach-certs
—host=my-release-cockroachdb-public -
Assign
roachto theadminrole (you only need to do this once): -
Exit the SQL shell and pod:
-
In a new terminal window, port-forward from your local machine to the
cockroachdb-publicservice: - Go to https://localhost:8080 and log in with the username and password you created earlier.
localhost because its certificate has been revoked, go to chrome://flags/#allow-insecure-localhost, enable “Allow invalid certificates for resources loaded from localhost”, and then restart the browser. Enabling this Chrome feature degrades security for all sites running on localhost, not just CockroachDB’s DB Console, so be sure to enable the feature only temporarily.
- Go to http://localhost:8080.
-
In the UI, verify that the cluster is running as expected:
- View the to ensure that all nodes successfully joined the cluster.
- Click the Databases tab on the left to verify that
bankis listed.
Step 5. Simulate node failure
Based on thereplicas: 3 line in the StatefulSet configuration, Kubernetes ensures that three pods/nodes are running at all times. When a pod/node fails, Kubernetes automatically creates another pod/node with the same network identity and persistent storage.
To see this in action:
-
Terminate one of the CockroachDB nodes:
- In the DB Console, the Cluster Overview will soon show one node as Suspect. As Kubernetes auto-restarts the node, watch how the node once again becomes healthy.
-
Back in the terminal, verify that the pod was automatically restarted:
Step 6. Add nodes
-
Use the
kubectl scalecommand to add a pod for another CockroachDB node: -
Verify that the pod for a fourth node,
cockroachdb-3, was added successfully:
Step 7. Remove nodes
To safely remove a node from your cluster, you must first decommission the node and only then adjust thespec.replicas value of your StatefulSet configuration to permanently remove it. This sequence is important because the decommissioning process lets a node finish in-flight requests, rejects any new requests, and transfers all range replicas and range leases off the node.
If you remove nodes without first telling CockroachDB to decommission them, you may cause data or even cluster unavailability. For more details about how this works and what to consider before removing nodes, see .
-
Launch a temporary interactive pod and use the
cockroach node statuscommand to get the internal IDs of nodes: -
Note the ID of the node with the highest number in its address (in this case, the address including
cockroachdb-3) and use the command to decommission it:
It’s important to decommission the node with the highest number in its address because, when you reduce the replica count, Kubernetes will remove the pod for that node.
stderr as it changes:
-
Once the node has been decommissioned, remove a pod from your StatefulSet:
Step 8. Stop the cluster
-
If you plan to restart the cluster, use the
minikube stopcommand. This shuts down the minikube virtual machine but preserves all the resources you created:You can restore the cluster to its previous state withminikube start. -
If you do not plan to restart the cluster, use the
minikube deletecommand. This shuts down and deletes the minikube virtual machine and all the resources you created, including persistent volumes:

