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 .
Limitations
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
Choose a way to deploy and maintain the CockroachDB cluster:- Public operator
- Helm package manager
- Manually apply our StatefulSet configuration and related files
Install the Operator
-
Apply the custom resource definition (CRD) for the Public operator:
-
By default, the Public operator is configured to install in the
cockroach-operator-systemnamespace and to manage CockroachDB instances for all namespaces on the cluster.
- To use these defaults, apply the Public operator manifest without modifying it:
- To change these defaults:
- Download the Public operator manifest:
- To use a custom namespace, edit all instances of
namespace: cockroach-operator-systemwith your desired namespace. - To limit the namespaces that will be monitored, set the
WATCH\_NAMESPACEenvironment variable in theDeploymentpod spec. This can be set to a single namespace or a comma-delimited set of namespaces. When set, only thoseCrdbClusterresources in the supplied namespace(s) will be reconciled. - Apply your local version of the Public operator manifest to the cluster:
- Download the Public operator manifest:
-
Set your current namespace to the one used by the Public operator. For example, to use the Public operator’s default namespace:
-
Validate that the operator is running:
Initialize the cluster
After a cluster managed by the Kubernetes operator is initialized, its Kubernetes labels cannot be modified. For more details, refer to Best practices.
-
Download
example.yaml, a custom resource that tells the operator how to configure the Kubernetes cluster.By default, this custom resource 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 .
By default, the operator will generate and sign 1 client and 1 node certificate to secure the cluster. This means that if you do not provide a CA, a
cockroach-generated CA is used. If you want to authenticate using your own CA, before proceeding to the next step.-
Apply
example.yaml:The operator will create a StatefulSet and initialize the nodes as a cluster. -
Check that the pods were created:
Each pod should have
READYstatus soon after being created.
Configure the cluster
-
Download and modify our :
-
Update
secretNamewith the name of the corresponding node secret. The secret names depend on your method for generating secrets. For example, if you follow the below steps usingcockroach cert, use this secret name: -
The StatefulSet configuration deploys CockroachDB into the
defaultnamespace. To use a different namespace, search forkind: RoleBindingand change itssubjects.namespaceproperty to the name of the namespace. Otherwise, afailed to read secretserror occurs when you attempt to follow the steps in Initialize the cluster.
By default, this manifest 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 certificates
The below steps use to quickly generate and sign the CockroachDB node and client certificates. Read our docs to learn about other methods of signing certificates.-
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:
-
Create the certificate and key pair for your CockroachDB nodes:
-
Upload the node certificate and key to the Kubernetes cluster as a secret:
-
Check that the secrets were created on the cluster:
Initialize the cluster
-
Use the config file you downloaded to create the StatefulSet that automatically creates 3 pods, each running a CockroachDB node:
-
Initialize the CockroachDB cluster:
-
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:
-
Run
cockroach initon one of the pods to complete the node startup process and have them join together as a cluster: -
Confirm that cluster initialization has completed successfully. The job should be considered successful and the Kubernetes pods should soon be considered
Ready:
-
Confirm that three pods are
If you are running a secure Helm deployment on Kubernetes 1.22 and later, you must migrate away from using the Kubernetes CA for cluster authentication. The recommended approach is to use
cert-manager for certificate management. For details, refer to .-
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.
By default, the Helm chart will generate and sign 1 client and 1 node certificate to secure the cluster. To authenticate using your own CA, see .
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.cockroachdb-statefulset.yaml file 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 logs for a pod, use kubectl logs <podname> rather than checking the log on the persistent volume.
Step 3. Use the built-in SQL client
To use the CockroachDB SQL client, first launch a secure pod running thecockroach binary.
-
Get a shell into the pod and start the CockroachDB :
-
Run some basic :
-
:
You will need this username and password to access the DB Console later.
-
Exit the SQL shell and pod:
-
Get a shell into the pod and start the CockroachDB :
-
Run some basic :
-
:
You will need this username and password to access the DB Console later.
-
Exit the SQL shell and pod:
client-secure.yaml file to launch a pod and keep it running indefinitely.
-
Download the file:
-
In the file, set the following values:
spec.serviceAccountName: my-release-cockroachdbspec.image: cockroachdb/cockroach: {your CockroachDB version}spec.volumes[0].project.sources[0].secret.name: my-release-cockroachdb-client-secret
-
Use the file to launch a pod 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 (e.g.,
cockroach node), repeat step 2 using the appropriatecockroachcommand. If you’d prefer to delete the pod and recreate it when needed, runkubectl 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 :$ 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. 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:

