This article assumes you have already .
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 .
- Public operator
All
kubectl steps should be performed in the . By default, this is cockroach-operator-system.Add nodes
- Public operator
- Manual configs
- Helm
Before scaling up CockroachDB, note the following :View the PVCs on the cluster:
- 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.
-
Run
kubectl get nodesto 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. -
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.
- 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.
-
The PVC names correspond to the pods they are bound to. For example, if the pods
cockroachdb-3,cockroachdb-4, andcockroachdb-5had been removed by scaling the cluster down from 6 to 3 nodes,datadir-cockroachdb-3,datadir-cockroachdb-4, anddatadir-cockroachdb-5would 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. - 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.
-
Update
nodesin 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.-
Apply the new settings to the cluster:
-
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.
- Public operator
- Manual configs
- Helm
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.
-
Update
nodesin 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. -
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.
-
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.
-
Download the Public operator manifest:
-
Uncomment the following lines in the Public operator manifest:
-
Reapply the Public operator manifest:
-
Validate that the Public operator is running:

