The CockroachDB operator is in .
Prerequisites and best practices
Kubernetes version
To deploy CockroachDB v25.1 or later, Kubernetes 1.30 or higher is required. Cockroach Labs strongly recommends that you use a Kubernetes version that is eligible for patch support by the Kubernetes project.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:operator: The chart to be installed first.cockroachdb: The CockroachDB application chart to be installed after the operator is ready.
Network
Service Name Indication (SNI) is an extension to the TLS protocol that 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 incompatible with SNI-based routing in the Kubernetes ingress controller. Instead, use a TCP load balancer for CockroachDB that is not shared with other services. If you want to secure your cluster to use TLS certificates for all network communications, Helm must be installed with RBAC privileges. Otherwise, you will get anattempt to grant extra privileges error.
Localities
CockroachDB clusters use localities to efficiently distribute replicas. This is especially important for multi-region deployments. With the , you specify mappings between locality levels and the location on a Kubernetes node where the value for that locality can be found. In cloud provider deployments (e.g., GKE, EKS, or AKS), thetopology.kubernetes.io/region and topology.kubernetes.io/zone values on Kubernetes nodes are populated by cloud provider. For further granularity, you can define arbitrary locality labels (e.g., province, datacenter, rack), but these need to be applied individually to the Kubernetes node when initialized so that CockroachDB can understand where the node lives and distribute replicas accordingly.
On bare metal Kubernetes deployments, you must plan a hierarchy of localities that suit your CockroachDB node distribution, then apply these values individually to nodes when they are initialized. Although you can set most of these values arbitrarily, you must set region and zone locations in the reserved topology.kubernetes.io/region and topology.kubernetes.io/zone namespaces, respectively.
For more information on how locality labels are used by CockroachDB, refer to the .
Architecture
The CockroachDB operator is only supported in environments with an ARM64 or AMD64 architecture.Resources
When starting Kubernetes, select machines with at least 4 vCPUs and 16 GiB of memory, and provision at least 2 vCPUs and 8 GiB 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.Storage
Kubernetes deployments use external persistent volumes that are often replicated by the provider. CockroachDB replicates data automatically, and this redundant layer of can impact performance. Using local volumes may improve performance.Multi-region deployments
The following deployment requirements and best practices apply to multi-region deployments with the :- Plan an operator deployment in each region. Each operator handles CockroachDB node management in its own region, so you must factor that there are multiple operator deployments into your upgrade and maintenance strategy to ensure availability.
- VPC peering and CoreDNS are needed to resolve services and discovery across regions. Refer to the documentation for your cloud solution to configure your cross-region network accordingly.
- Make sure that region is part of your locality configuration and nodes are tagged consistently with their deployment region. For deployments with a cloud service provider this is handled automatically, but must be applied manually for bare metal deployments.
- A single certificate authority (CA) across all regions is required. One namespace per region is recommended to simplify certificate management.
Step 1. Start Kubernetes
You can use the hosted Google Kubernetes Engine (GKE) service, hosted Amazon Elastic Kubernetes Service (EKS), or Microsoft Azure Kubernetes Service (AKS) to quickly start Kubernetes.Hosted GKE
-
Complete the Before You Begin steps described in the Google Kubernetes Engine Quickstart documentation.
This includes installing
gcloud, which is used to create and delete Kubernetes Engine clusters, andkubectl, which is the command-line tool used to manage Kubernetes from your workstation. The documentation offers the choice of using Google’s Cloud Shell product or using a local shell on your machine. Choose to use a local shell if you want to be able to view the DB Console using the steps in this guide. -
From your local workstation, start the Kubernetes cluster, specifying one of the available regions (e.g.,
us-east1). The process can take a few minutes, so do not move on to the next step until you see aCreating cluster cockroachdb...donemessage and details about your cluster.
Since this region can differ from your default
gcloud region, be sure to include the --region flag to run gcloud commands against this cluster.
This creates GKE instances and joins them into a single Kubernetes cluster named cockroachdb. The --region flag specifies a regional three-zone cluster, and --num-nodes specifies one Kubernetes worker node in each zone.--machine-type flag tells the node pool to use the n2-standard-4 machine type (4 vCPUs, 16 GB memory), which meets our .
Consider creating another, dedicated node group for the operator pod for system resource availability.
-
Get the email address associated with your Google Cloud account:
The preceding command returns your email address in all lowercase. However, in the next step, you must enter the address using the accurate capitalization. For example, if your address is
YourName@example.com, you must useYourName@example.comand notyourname@example.com. -
Create the RBAC roles CockroachDB needs for running on GKE, using the address from the previous step:
Hosted EKS
-
Complete the steps described in the EKS Getting Started documentation.
This includes installing and configuring the AWS CLI and
eksctl, which is the command-line tool used to create and delete Kubernetes clusters on EKS, andkubectl, which is the command-line tool used to manage Kubernetes from your workstation. If you are running EKS-Anywhere, CockroachDB requires that you configure your default storage class to auto-provision persistent volumes. Alternatively, you can define a custom storage configuration as required by your install pattern. -
From your local workstation, start the Kubernetes cluster:
To ensure that all 3 nodes can be placed into a different availability zone, you may want to first confirm that at least 3 zones are available in the region for your account.
Cluster provisioning usually takes between 10 and 15 minutes. Do not move on to the next step until you see a message like
[✔] EKS cluster "cockroachdb" in "us-east-1" region is readyand details about your cluster.This creates EKS instances and joins them into a single Kubernetes cluster namedcockroachdb. The--node-typeflag tells the node pool to use the m6i.xlarge instance type (4 vCPUs, 16 GB memory), which meets our . Consider creating another, dedicated node group for the operator pod for system resource availability. -
Open the AWS CloudFormation console to verify that the stacks
eksctl-cockroachdb-clusterandeksctl-cockroachdb-nodegroup-standard-workerswere successfully created. Be sure that your region is selected in the console.
Hosted AKS
-
Complete the Before you begin, Define environment variables, and Create a resource groups steps described in the AKS quickstart guide. This includes setting up the Azure CLI and the
aztool, which is the command-line tool to create and manage Azure cloud resources. Set the environment variables as desired for your CockroachDB deployment. For these instructions, set theMY_AKS_CLUSTER_NAMEvariable tocockroachdb. Do not follow the Create an AKS cluster steps or following sections of the AKS quickstart guide, as these topics will be described specifically for CockroachDB in this documentation. -
From your workstation, create the Kubernetes cluster:
-
Configure authentication for the . The operator can use Azure Managed Identities if they are configured.
If Azure Managed Identities are not configured for the , create an application in your Azure tenant and create a secret named
azure-cluster-identity-credentials-secretthat containsAZURE_TENANT_ID,AZURE_CLIENT_ID, andAZURE_CLIENT_SECRETto hold the application credentials. You can use the following example YAML to define this application:For more information on how to use these variables, refer to theAzure.Identitydocumentation.
Bare metal deployments
For bare metal deployments, the specific Kubernetes infrastructure deployment steps should be similar to those described in Hosted GKE and Hosted EKS.- You must plan a hierarchy of locality labels that suit your CockroachDB node distribution, then apply these labels individually to nodes when they are initialized. Although you can set most of these values arbitrarily, you must set region and zone locations in the reserved
topology.kubernetes.io/regionandtopology.kubernetes.io/zonenamespaces, respectively.
Step 2. Start CockroachDB
Install the operator sub-chart
-
Check out the CockroachDB Helm repository from GitHub:
-
Set your environment variables. This step is optional but recommended in order to use the example commands and templates described in the following instructions. Note the default Kubernetes namespace of
cockroach-ns. -
Install the operator sub-chart:
Initialize the cluster
-
Open
cockroachdb-parent/charts/cockroachdb/values.yaml, a values file that tells Helm how to configure the Kubernetes cluster, in your text editor. -
Modify the
cockroachdb.crdbCluster.regionssection to describe the number of CockroachDB nodes to deploy and what region(s) to deploy them in. Replace the defaultcloudProviderwith the appropriate value (gcp,aws,azure). For bare metal deployments, you can remove thecloudProviderfield. The following example initializes three nodes on Google Cloud in theus-central1region:
If you intend to deploy CockroachDB nodes across multiple different regions, follow the additional steps described in Deploy across multiple regions.
-
Modify
cockroachdb.crdbCluster.podTemplate.spec.resourcesin the values file with the CPU and memory limits and requests for each node to use. For example, to define default values of 4vCPU and 16GiB of memory:For more information on configuring node resource allocation, refer to -
Modify the TLS configuration as desired. For a secure deployment, set
cockroachdb.tls.enabledin the values file totrue. You can either allow the operator to generate self-signed certificates, provide a custom CA certificate and generate other certificates, or use your own certificates.-
All self-signed certificates: By default, the certificates are created automatically by a self-signer utility, which requires no configuration beyond setting a custom certificate duration if desired. This utility creates self-signed certificates for the nodes and root client which are stored in a secret. You can see these certificates by running
kubectl get secrets:If you are deploying on OpenShift you must also setcockroachdb.tls.selfSigner.securityContext.enabledtofalseto mitigate stricter security policies.
-
All self-signed certificates: By default, the certificates are created automatically by a self-signer utility, which requires no configuration beyond setting a custom certificate duration if desired. This utility creates self-signed certificates for the nodes and root client which are stored in a secret. You can see these certificates by running
-
Custom CA certificate: If you wish to supply your own CA certificates to the deployed nodes but allow automatic generation of client certificates, create a Kubernetes secret with the custom CA certificate. To perform these steps using the
cockroach certcommand:Setcockroachdb.tls.selfSigner.caProvidedtotrueand specify the secret where the certificate is stored:If you are deploying on OpenShift you must also setcockroachdb.tls.selfSigner.securityContext.enabledtofalseto mitigate stricter security policies. -
All custom certificates: Set up your certificates and load them into your Kubernetes cluster as secrets using the following commands:
The subject alternative names are based on a release called
my-release in the cockroach-ns namespace. Make sure they match the services created with the release during Helm install.
If you wish to supply certificates with cert-manager, set cockroachdb.tls.certManager.enabled to true, and cockroachdb.tls.certManager.issuer to an IssuerRef (as they appear in certificate resources) pointing to a clusterIssuer or issuer that you have set up in the cluster:cert-manager, the secret will contain files named: ca.crt, tls.crt, and tls.key.
For CockroachDB, rename these files as applicable to match the following naming scheme: ca.crt, node.crt, node.key, client.root.crt, and client.root.key.
Add the following to the values file:
- : The name of the Kubernetes secret that contains the generated client certificate and key.
- : The name of the Kubernetes secret that contains the generated node certificate and key.
-
In
cockroachdb.crdbCluster.localityMappings, provide locality mappings that define locality levels and map them to node labels where the locality information of each Kubernetes node is stored. When CockroachDB is initialized on a node, it processes these values as though they are provided through the flag. IflocalityMappingsis not configured, by default the uses theregionandzonelocality labels, mapped implicitly to thetopology.kubernetes.io/regionandtopology.kubernetes.io/zonenode labels.- In cloud provider deployments, the
topology.kubernetes.io/regionandtopology.kubernetes.io/zonevalues on a node are populated by the cloud provider. - In bare metal deployments, the
topology.kubernetes.io/regionandtopology.kubernetes.io/zonenode label values are not set implicitly by a cloud provider when initializing the node, so you must set them manually or configure custom locality labels.
cockroachdb.crdbCluster.localityMappingslist. Any customlocalityMappingsconfiguration overrides the defaultregionandzoneconfiguration, so if you append an additional locality level but wish to keep theregionandzonelabels you must declare them manually. The following example uses the existingregionandzonelabels and adds an additionaldatacenterlocality mapping that is more granular thanzone. This example declares that thedclocality information is stored in theexample.datacenter.localitynode label:The list oflocalityMappingsis processed in a top-down hierarchy, where each entry is processed as a lower locality level than the previous locality. In this example, if a Kubernetes node is initialized in theus-central1region,us-central1-czone, anddc2datacenter, itscockroach start --localityflag would be equivalent to the following:Optionally, review thecockroachdb.crdbCluster.podTemplate.spec.topologySpreadConstraintsconfiguration and settopologyKeyto thenodeLabelvalue of a locality level that has distinct values for each node. By default the lowest locality level iszone, so the following configuration sets that value as thetopologyKey:For more information on localities and topology planning, see the . - In cloud provider deployments, the
-
Modify other relevant parts of the configuration such as other
topologySpreadConstraintsfields,service.ports, and others as needed for your configuration. -
Run the following command to install the CockroachDB chart using Helm:
You can override the default parameters using the
--set key=value[,key=value]argument while installing the chart: -
Verify that the cluster has initialized and pods are now running:
Deploy across multiple regions
The Helm chart supports specifying multiple region definitions incockroachdb.crdbCluster.regions with their respective node counts. Make sure to review the prerequisites and best practices for a multi-region deployment.
For each region, modify the regions configuration as described in Initialize the cluster and perform helm install against the respective Kubernetes cluster.
The following example shows a configuration across two regions, us-central1 and us-east1, with 3 nodes in each cluster:
- Verify that the domain matches
cockroachdb.clusterDomainin the values file. - Ensure that
cockroachdb.crdbCluster.regionscaptures the information for regions that have already been deployed, including the current region. This allows CockroachDB in the current region to connect to clusters deployed in the existing regions.
Step 3. Use the built-in SQL client
To use the CockroachDB SQL client, follow these steps to launch a secure pod running thecockroach binary.
-
Download the secure client Kubernetes application:
This client tool logs into CockroachDB as
root using the root certificates.-
Edit the yaml file with the following values:
spec.serviceAccountName: my-release-cockroachdbspec.image: cockroachdb/cockroach:spec.volumes[0].project.sources[0].secret.name: my-release-cockroachdb-client-secret
-
Launch a pod using this file and keep it running indefinitely:
-
Get a shell into the pod and start the CockroachDB :
This pod will continue running indefinitely, so any time you need to reopen the built-in SQL client or run any other cockroach client commands (e.g., cockroach node), repeat this step using the appropriate cockroach command. If you’d prefer to delete the pod and recreate it when needed, run
kubectl delete pod cockroachdb-client-secure. -
Run some basic :
-
:
You will need this username and password to access the DB Console later.
- Exit the SQL shell and 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 : -
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:Run theport-forwardcommand on the same machine as the web browser in which you want to view the DB Console. If you have been running these commands from a cloud instance or other non-local shell, you will not be able to view the UI without configuringkubectllocally and running the precedingport-forwardcommand on your local machine. -
Go to
https://localhost:8080and log in with the username and password you created earlier.
If you are using Google Chrome, and get an error about not being able to reach
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. This degrades security for all sites running on localhost, not just CockroachDB’s DB Console, so enable the feature only temporarily.- In the DB Console, 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.
Next steps
Read the following pages for detailed information on cluster scaling, certificate management, resource management, best practices, and other cluster operation details:Examples
Authenticate with cockroach cert
The following example uses to generate and sign the CockroachDB node and client certificates. To learn more about the supported methods of signing certificates, refer to .
-
Create two directories:
-
Create the CA certificate and key pair:
-
Create a client certificate and key pair for the root user:
-
Upload the client certificate and key to the Kubernetes cluster as a secret, renaming them to the filenames required by the :
-
Create the certificate and key pair for your CockroachDB nodes, specifying the namespace you used when deploying the cluster. This example uses the
cockroach-nsnamespace: -
Upload the node certificate and key to the Kubernetes cluster as a secret, renaming them to the filenames required by the :
-
Check that the secrets were created on the cluster:
-
Add
cockroachdb.tls.externalCertificates.certificates.nodeSecretNameandcockroachdb.tls.externalCertificates.certificates.nodeClientSecretNameto the values file used to deploy the cluster:

