Skip to main content
This article assumes you have already .
This page explains how to add and remove CockroachDB nodes on Kubernetes. This page is for Kubernetes deployments that are not using the CockroachDB operator. For guidance specific to the CockroachDB operator, read .
This page describes a Kubernetes deployment method that is considered “legacy” and will not be supported in a future release of CockroachDB. New CockroachDB deployments on Kubernetes are recommended to use the newer, fully-featured that’s easier to deploy and supports scaling of multi-region clusters. To migrate an existing deployment to use the CockroachDB operator, read the and migration guides.For more information on legacy Kubernetes deployments and support timelines, read the .
All kubectl steps should be performed in the . By default, this is cockroach-operator-system.
If you , substitute kubectl with oc in the following commands.

Add nodes

Before scaling up CockroachDB, note the following :
  • Each CockroachDB node (running in its own pod) should run on a separate Kubernetes worker node.
  • Each availability zone should have the same number of CockroachDB nodes.
If your cluster has 3 CockroachDB nodes distributed across 3 availability zones (as in our ), we recommend scaling up by a multiple of 3 to retain an even distribution of nodes. You should therefore scale up to a minimum of 6 CockroachDB nodes, with 2 nodes in each zone.
  1. Run kubectl get nodes to list the worker nodes in your Kubernetes cluster. There should be at least as many worker nodes as pods you plan to add. This ensures that no more than one pod will be placed on each worker node.
  2. If you need to add worker nodes, resize your GKE cluster by specifying the desired number of worker nodes in each zone:
    This example distributes 2 worker nodes across the default 3 zones, raising the total to 6 worker nodes.
  3. If you are adding nodes after previously scaling down, and have not enabled automatic PVC pruning, you must first manually delete any persistent volumes that were orphaned by node removal.
Due to a known issue, automatic pruning of PVCs is currently disabled by default. This means that after decommissioning and removing a node, the Public operator will not remove the persistent volume that was mounted to its pod.
View the PVCs on the cluster:
  1. The PVC names correspond to the pods they are bound to. For example, if the pods cockroachdb-3, cockroachdb-4, and cockroachdb-5 had been removed by scaling the cluster down from 6 to 3 nodes, datadir-cockroachdb-3, datadir-cockroachdb-4, and datadir-cockroachdb-5 would be the PVCs for the orphaned persistent volumes. To verify that a PVC is not currently bound to a pod:
    The output will include the following line:
    If the PVC is bound to a pod, it will specify the pod name.
  2. Remove the orphaned persistent volumes by deleting their PVCs:
Before deleting any persistent volumes, be sure you have a backup copy of your data. Data cannot be recovered once the persistent volumes are deleted. For more information, see the Kubernetes documentation.
  1. Update nodes in the Public operator’s custom resource, which you downloaded when , with the target size of the CockroachDB cluster. This value refers to the number of CockroachDB nodes, each running in one pod:
Note that you must scale by updating the nodes value in the custom resource. Using kubectl scale statefulset <cluster-name> --replicas=4 will result in new pods immediately being terminated.
  1. Apply the new settings to the cluster:
  2. Verify that the new pods were successfully started:
    Each pod should be running in one of the 6 worker nodes.

Remove nodes

Do not scale down to fewer than 3 nodes. This is considered an anti-pattern on CockroachDB and will cause errors.
Due to a known issue, automatic pruning of PVCs is currently disabled by default. This means that after decommissioning and removing a node, the Public 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 Add nodes.If you want to enable the Public operator to automatically prune PVCs when scaling down, see Automatic PVC pruning. However, note that this workflow is currently unsupported.Before scaling down CockroachDB, note the following :
  • Each availability zone should have the same number of CockroachDB nodes.
If your nodes are distributed across 3 availability zones (as in our ), we recommend scaling down by a multiple of 3 to retain an even distribution. If your cluster has 6 CockroachDB nodes, you should therefore scale down to 3, with 1 node in each zone.
  1. Update nodes in the custom resource, which you downloaded when , with the target size of the CockroachDB cluster. For instance, to scale down to 3 nodes:
    Before removing a node, the Public operator first decommissions the node. This lets a node finish in-flight requests, rejects any new requests, and transfers all range replicas and range leases off the node.
  2. Apply the new settings to the cluster:
    The Public operator will remove nodes from the cluster one at a time, starting from the pod with the highest number in its address.
  3. Verify that the pods were successfully removed:

Automatic PVC pruning

To enable the Public operator to automatically remove persistent volumes when scaling down a cluster, turn on automatic PVC pruning through a feature gate.
This workflow is unsupported and should be enabled at your own risk.
  1. Download the Public operator manifest:
  2. Uncomment the following lines in the Public operator manifest:
  3. Reapply the Public operator manifest:
  4. Validate that the Public operator is running: