This article assumes you have already .
All
kubectl steps should be performed in the . By default, this is cockroach-operator-system.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.
-
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 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 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.
If you want to enable the Operator to automatically prune PVCs when scaling down, see Automatic PVC pruning. However, note that this workflow is currently unsupported.
- 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 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 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 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 Operator manifest:
-
Uncomment the following lines in the Operator manifest:
-
Reapply the Operator manifest:
-
Validate that the Operator is running:
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.
-
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. -
Add worker nodes if necessary:
-
On GKE, resize your cluster. If you deployed a regional cluster as we recommended, you will use
--num-nodesto specify the desired number of worker nodes in each zone. For example: - On EKS, resize your Worker Node Group.
- On GCE, resize your Managed Instance Group.
- On AWS, resize your Auto Scaling Group.
-
On GKE, resize your cluster. If you deployed a regional cluster as we recommended, you will use
-
Edit your StatefulSet configuration to add pods for each new CockroachDB node:
-
Verify that the new pod started successfully:
- You can also open the in the DB Console to ensure that the fourth node successfully joined the cluster.
Remove nodes
Do not scale down to fewer than 3 nodes. This is considered an anti-pattern on CockroachDB and will cause errors. Before removing a node from your cluster, you must first decommission 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.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 .
-
Use the command to get the internal IDs of nodes. For example, if you followed the steps in to launch a secure client pod, get a shell into the
cockroachdb-client-securepod:The pod uses therootclient certificate created earlier to initialize the cluster, so there’s no CSR approval required. -
Use the command to decommission the node with the highest number in its address, specifying its ID (in this example, node ID
4because its address iscockroachdb-3):
You must decommission the node with the highest number in its address. Kubernetes will remove the pod for the node with the highest number in its address when you reduce the replica count.
stderr as it changes:
-
Once the node has been decommissioned, scale down your StatefulSet:
-
Verify that the pod was successfully removed:
-
You should also remove the persistent volume that was mounted to the pod. Get the persistent volume claims for the volumes:
-
Verify that the PVC with the highest number in its name is no longer mounted to a pod:
-
Remove the persistent volume by deleting the PVC:
Add nodes
Before scaling CockroachDB, ensure that your Kubernetes cluster has enough worker nodes to host the number of pods you want to add. This is to ensure that two pods are not placed on the same worker node, as recommended in our . For example, if you want to scale from 3 CockroachDB nodes to 4, your Kubernetes cluster should have at least 4 worker nodes. You can verify the size of your Kubernetes cluster by runningkubectl get nodes.
-
Edit your StatefulSet configuration to add another pod for the new CockroachDB node:
-
Get the name of the
PendingCSR for the new pod:If you do not see aPendingCSR, wait a minute and try again. -
Examine the CSR for the new pod:
-
If everything looks correct, approve the CSR for the new pod:
-
Verify that the new pod started successfully:
- You can also open the in the DB Console to ensure that the fourth node successfully joined the cluster.
Remove nodes
Do not scale down to fewer than 3 nodes. This is considered an anti-pattern on CockroachDB and will cause errors. Before removing a node from your cluster, you must first decommission 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. 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 .-
Use the command to get the internal IDs of nodes. For example, if you followed the steps in to launch a secure client pod, get a shell into the
cockroachdb-client-securepod:The pod uses therootclient certificate created earlier to initialize the cluster, so there’s no CSR approval required. -
Use the command to decommission the node with the highest number in its address, specifying its ID (in this example, node ID
4because its address ismy-release-cockroachdb-3): You must decommission the node with the highest number in its address. Kubernetes will remove the pod for the node with the highest number in its address when you reduce the replica count.You’ll then see the decommissioning status print tostderras it changes:Once the node has been fully decommissioned, you’ll see a confirmation: -
Once the node has been decommissioned, scale down your StatefulSet:
-
Verify that the pod was successfully removed:
-
You should also remove the persistent volume that was mounted to the pod. Get the persistent volume claims for the volumes:
-
Verify that the PVC with the highest number in its name is no longer mounted to a pod:
-
Remove the persistent volume by deleting the PVC:

