> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy CockroachDB in a Single Kubernetes Cluster (Insecure)

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

This page shows you how to start and stop a 3-node CockroachDB insecure test cluster in a single [Kubernetes](http://kubernetes.io/) cluster, using one of the following:

* Manual [StatefulSet](http://kubernetes.io/docs/concepts/abstractions/controllers/statefulsets) configuration
* [Helm](https://helm.sh/) package manager for Kubernetes

<Danger>
  The `--insecure` flag used in this tutorial is intended for non-production testing only. To run CockroachDB in production, use a secure cluster instead.
</Danger>

The steps below demonstrate how to quickly deploy and interact with an insecure test cluster. To learn about authenticating, configuring, scaling, and upgrading a CockroachDB cluster on Kubernetes, see <InternalLink path="kubernetes-overview">Kubernetes Overview</InternalLink>.

<Tip>
  To try CockroachDB Cloud instead of running CockroachDB yourself, refer to the <InternalLink version="cockroachcloud" path="quickstart">Cloud Quickstart</InternalLink>.
</Tip>

## Before you begin

Before getting started, it's helpful to review some Kubernetes-specific terminology and current limitations.

* [Kubernetes terminology](#kubernetes-terminology)
* [Best practices](#best-practices)

### Kubernetes terminology

| Feature                                                                                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [node](https://kubernetes.io/docs/concepts/architecture/nodes)                          | A physical or virtual machine. In this tutorial, you'll create GCE or AWS instances and join them as worker nodes into a single Kubernetes cluster from your local workstation.                                                                                                                                                                                                                                                                                                                                                                     |
| [pod](http://kubernetes.io/docs/user-guide/pods)                                        | A pod is a group of one or more Docker containers. In this tutorial, each pod will run on a separate Kubernetes node and include one Docker container running a single CockroachDB node. You'll start with 3 pods and grow to 4.                                                                                                                                                                                                                                                                                                                    |
| [StatefulSet](http://kubernetes.io/docs/concepts/abstractions/controllers/statefulsets) | A StatefulSet is a group of pods treated as stateful units, where each pod has distinguishable network identity and always binds back to the same persistent storage on restart. StatefulSets are considered stable as of Kubernetes version 1.9 after reaching beta in version 1.5.                                                                                                                                                                                                                                                                |
| [persistent volumes](http://kubernetes.io/docs/user-guide/persistent-volumes)           | A persistent volume is a piece of networked storage (Persistent Disk on GCE, Elastic Block Store on AWS) mounted into a pod. The lifetime of a persistent volume is decoupled from the lifetime of the pod that's using it, ensuring that each CockroachDB node binds back to the same storage on restart.  This tutorial assumes that dynamic volume provisioning is available. When that is not the case, [persistent volume claims](http://kubernetes.io/docs/user-guide/persistent-volumes#persistentvolumeclaims) need to be created manually. |

### Best practices

#### Kubernetes version

To deploy CockroachDB v25.2, 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](https://kubernetes.io/releases).

#### Public operator

* The Public operator deploys clusters in a single region. For multi-region deployments using manual configs, Cockroach Labs recommends using the <InternalLink path="cockroachdb-operator-overview">CockroachDB operator</InternalLink> which is designed to support multi-region deployments. For guidance on how to force multi-region support with the Public operator, see <InternalLink path="orchestrate-cockroachdb-with-kubernetes-multi-cluster">Orchestrate CockroachDB Across Multiple Kubernetes Clusters</InternalLink>.
* Using the Public operator, you can give a new cluster an arbitrary number of [labels](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels). However, a cluster's labels cannot be modified after it is deployed. To track the status of this limitation, refer to [#993](https://github.com/cockroachdb/cockroach-operator/issues/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:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
Error: UPGRADE FAILED: template: cockroachdb/templates/tests/client.yaml:6:14: executing "cockroachdb/templates/tests/client.yaml" at <.Values.networkPolicy.enabled>: nil pointer evaluating interface {}.enabled
```

The public Helm chart is currently not under active development, and no new features are planned. However, Cockroach Labs remains committed to fully supporting the Helm chart by addressing defects, providing security patches, and addressing breaking changes due to deprecations in Kubernetes APIs.

A deprecation notice for the public Helm chart will be provided to customers a minimum of 6 months in advance of actual deprecation.

#### 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 <InternalLink path="configure-cockroachdb-kubernetes#memory-and-cpu">Resource management</InternalLink>.

<a id="storage" />

#### 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](https://kubernetes.io/docs/concepts/storage/volumes#local) may improve performance.

## Step 1. Start Kubernetes

You can use the hosted [Google Kubernetes Engine (GKE)](#hosted-gke) service or the hosted [Amazon Elastic Kubernetes Service (EKS)](#hosted-eks) to quickly start Kubernetes.

<Note>
  GKE or EKS are not required to run CockroachDB on Kubernetes. A manual GCE or AWS cluster with the [minimum recommended Kubernetes version](#kubernetes-version) and at least 3 pods, each presenting [sufficient resources](#resources) to start a CockroachDB node, can also be used.
</Note>

### Hosted GKE

1. Complete the **Before You Begin** steps described in the [Google Kubernetes Engine Quickstart](https://cloud.google.com/kubernetes-engine/docs/quickstart) documentation.

   This includes installing `gcloud`, which is used to create and delete Kubernetes Engine clusters, and `kubectl`, which is the command-line tool used to manage Kubernetes from your workstation.

<Tip>
  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.
</Tip>

2. From your local workstation, start the Kubernetes cluster, specifying one of the available [regions](https://cloud.google.com/compute/docs/regions-zones#available) (e.g., `us-east1`):

<Tip>
  Since this region can differ from your default `gcloud` region, be sure to include the `--region` flag to run `gcloud` commands against this cluster.
</Tip>

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ gcloud container clusters create cockroachdb --machine-type n2-standard-4 --region {region-name} --num-nodes 1
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
Creating cluster cockroachdb...done.
```

This creates GKE instances and joins them into a single Kubernetes cluster named `cockroachdb`. The `--region` flag specifies a [regional three-zone cluster](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-regional-cluster), and `--num-nodes` specifies one Kubernetes worker node in each zone.

The `--machine-type` flag tells the node pool to use the [`n2-standard-4`](https://cloud.google.com/compute/docs/machine-types#standard_machine_types) machine type (4 vCPUs, 16 GB memory), which meets our <InternalLink path="recommended-production-settings#basic-hardware-recommendations">recommended CPU and memory configuration</InternalLink>.

The process can take a few minutes, so do not move on to the next step until you see a `Creating cluster cockroachdb...done` message and details about your cluster.

3. Get the email address associated with your Google Cloud account:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ gcloud info | grep Account
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   Account: [your.google.cloud.email@example.org]
   ```

<Danger>
  This 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](mailto:YourName@example.com), you must use [YourName@example.com](mailto:YourName@example.com) and not [yourname@example.com](mailto:yourname@example.com).
</Danger>

4. [Create the RBAC roles](https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control#prerequisites_for_using_role-based_access_control) CockroachDB needs for running on GKE, using the address from the previous step:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl create clusterrolebinding $USER-cluster-admin-binding \
   --clusterrole=cluster-admin \
   --user={your.google.cloud.email@example.org}
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   clusterrolebinding.rbac.authorization.k8s.io/your.username-cluster-admin-binding created
   ```

### Hosted EKS

1. Complete the steps described in the [EKS Getting Started](https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl) 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, and `kubectl`, which is the command-line tool used to manage Kubernetes from your workstation.

<Note>
  If you are running [EKS-Anywhere](https://aws.amazon.com/eks/eks-anywhere), CockroachDB requires that you [configure your default storage class](https://kubernetes.io/docs/tasks/administer-cluster/change-default-storage-class) to auto-provision persistent volumes. Alternatively, you can define a custom storage configuration as required by your install pattern.
</Note>

2. From your local workstation, start the Kubernetes cluster:

<Tip>
  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](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones#availability-zones-describe) for your account.
</Tip>

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ eksctl create cluster \
--name cockroachdb \
--nodegroup-name standard-workers \
--node-type m5.xlarge \
--nodes 3 \
--nodes-min 1 \
--nodes-max 4 \
--node-ami auto
```

This creates EKS instances and joins them into a single Kubernetes cluster named `cockroachdb`. The `--node-type` flag tells the node pool to use the [`m5.xlarge`](https://aws.amazon.com/ec2/instance-types) instance type (4 vCPUs, 16 GB memory), which meets our <InternalLink path="recommended-production-settings#basic-hardware-recommendations">recommended CPU and memory configuration</InternalLink>.

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 ready` and details about your cluster.

3. Open the [AWS CloudFormation console](https://console.aws.amazon.com/cloudformation/home) to verify that the stacks `eksctl-cockroachdb-cluster` and `eksctl-cockroachdb-nodegroup-standard-workers` were successfully created. Be sure that your region is selected in the console.

## Step 2. Start CockroachDB

Choose how you want to deploy and maintain the CockroachDB cluster.

1. From your local workstation, use our <InternalLink path="cockroach/cloud/kubernetes/cockroachdb-statefulset.yaml">`cockroachdb-statefulset.yaml`</InternalLink> file to create the StatefulSet that automatically creates 3 pods, each with a CockroachDB node running inside it.

   Download <InternalLink path="cockroach/cloud/kubernetes/cockroachdb-statefulset.yaml">`cockroachdb-statefulset.yaml`</InternalLink>:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ curl -O https://www.cockroachlabs.com/docs/files/cockroach/cloud/kubernetes/cockroachdb-statefulset.yaml
   ```

<Note>
  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 <InternalLink path="configure-cockroachdb-kubernetes?filters=manual">Resource management</InternalLink>.
</Note>

Use the file to create the StatefulSet and start the cluster:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ kubectl create -f cockroachdb-statefulset.yaml
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
service/cockroachdb-public created
service/cockroachdb created
poddisruptionbudget.policy/cockroachdb-budget created
statefulset.apps/cockroachdb created
```

Alternatively, if you'd rather start with a configuration file that has been customized for performance:

1. Download our <InternalLink path="cockroach/cloud/kubernetes/performance/cockroachdb-statefulset-insecure.yaml">performance version of `cockroachdb-statefulset-insecure.yaml`</InternalLink>:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ curl -O https://www.cockroachlabs.com/docs/files/cockroach/cloud/kubernetes/performance/cockroachdb-statefulset-insecure.yaml
   ```
2. Modify the file wherever there is a `TODO` comment.
3. Use the file to create the StatefulSet and start the cluster:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl create -f cockroachdb-statefulset-insecure.yaml
   ```
4. Confirm that three pods are `Running` successfully. Note that they will not be considered `Ready` until after the cluster has been initialized:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl get pods
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   NAME            READY     STATUS    RESTARTS   AGE
   cockroachdb-0   0/1       Running   0          2m
   cockroachdb-1   0/1       Running   0          2m
   cockroachdb-2   0/1       Running   0          2m
   ```
5. Confirm that the persistent volumes and corresponding claims were created successfully for all three pods:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl get persistentvolumes
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   NAME                                       CAPACITY   ACCESSMODES   RECLAIMPOLICY   STATUS    CLAIM                           REASON    AGE
   pvc-52f51ecf-8bd5-11e6-a4f4-42010a800002   1Gi        RWO           Delete          Bound     default/datadir-cockroachdb-0             26s
   pvc-52fd3a39-8bd5-11e6-a4f4-42010a800002   1Gi        RWO           Delete          Bound     default/datadir-cockroachdb-1             27s
   pvc-5315efda-8bd5-11e6-a4f4-42010a800002   1Gi        RWO           Delete          Bound     default/datadir-cockroachdb-2             27s
   ```
6. Use our [`cluster-init.yaml`](https://www.cockroachlabs.com/docs/files/cockroach/cloud/kubernetes/cluster-init.yaml) file to perform a one-time initialization that joins the CockroachDB nodes into a single cluster:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl create \
   -f https://www.cockroachlabs.com/docs/files/cockroach/cloud/kubernetes/cluster-init.yaml
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   job.batch/cluster-init created
   ```
7. Confirm that cluster initialization has completed successfully. The job should be considered successful and the Kubernetes pods should soon be considered `Ready`:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl get job cluster-init
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   NAME           COMPLETIONS   DURATION   AGE
   cluster-init   1/1           7s         27s
   ```

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl get pods
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   NAME                 READY   STATUS      RESTARTS   AGE
   cluster-init-cqf8l   0/1     Completed   0          56s
   cockroachdb-0        1/1     Running     0          7m51s
   cockroachdb-1        1/1     Running     0          7m51s
   cockroachdb-2        1/1     Running     0          7m51s
   ```

<Tip>
  The StatefulSet configuration sets all CockroachDB nodes to log to `stderr`, so if you ever need access to a pod/node's logs to troubleshoot, use `kubectl logs <podname>` rather than checking the log on the persistent volume.
</Tip>

## Step 3. Use the built-in SQL client

1. Launch a temporary interactive pod and start the <InternalLink path="cockroach-sql">built-in SQL client</InternalLink> inside it:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl run cockroachdb -it \
   --image=cockroachdb/cockroach:v25.2.15 \
   --rm \
   --restart=Never \
   -- sql \
   --insecure \
   --host=cockroachdb-public
   ```
2. Run some basic <InternalLink path="learn-cockroachdb-sql">CockroachDB SQL statements</InternalLink>:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > CREATE DATABASE bank;
   ```

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > CREATE TABLE bank.accounts (
       id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
         balance DECIMAL
     );
   ```

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > INSERT INTO bank.accounts (balance)
     VALUES
         (1000.50), (20000), (380), (500), (55000);
   ```

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > SELECT * FROM bank.accounts;
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
                      id                  | balance
   +--------------------------------------+---------+
     6f123370-c48c-41ff-b384-2c185590af2b |     380
     990c9148-1ea0-4861-9da7-fd0e65b0a7da | 1000.50
     ac31c671-40bf-4a7b-8bee-452cff8a4026 |     500
     d58afd93-5be9-42ba-b2e2-dc00dcedf409 |   20000
     e6d8f696-87f5-4d3c-a377-8e152fdc27f7 |   55000
   (5 rows)
   ```
3. Exit the SQL shell and delete the temporary pod:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > \q
   ```

## Step 4. Access the DB Console

To access the cluster's <InternalLink path="ui-overview">DB Console</InternalLink>:

1. In a new terminal window, port-forward from your local machine to the `cockroachdb-public` service: `$ kubectl port-forward service/cockroachdb-public 8080 `

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl port-forward service/cockroachdb-public 8080
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   Forwarding from 127.0.0.1:8080 -> 8080
   ```

<Note>
  The `port-forward` command must be run 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 configuring `kubectl` locally and running the above `port-forward` command on your local machine.
</Note>

2. Go to [http://localhost:8080](http://localhost:8080/).
3. In the UI, verify that the cluster is running as expected:
   * View the <InternalLink path="ui-cluster-overview-page#node-list">Node List</InternalLink> to ensure that all nodes successfully joined the cluster.
   * Click the **Databases** tab on the left to verify that `bank` is listed.

## Step 5. Simulate node failure

Based on the `replicas: 3` line in the StatefulSet configuration, Kubernetes ensures that three pods/nodes are running at all times. When a pod/node fails, Kubernetes automatically creates another pod/node with the same network identity and persistent storage.

To see this in action:

1. Terminate one of the CockroachDB nodes: `$ kubectl delete pod cockroachdb-2 ``pod "cockroachdb-2" deleted `

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl delete pod cockroachdb-2
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   pod "cockroachdb-2" deleted
   ```
2. In the DB Console, the **Cluster Overview** will soon show one node as **Suspect**. As Kubernetes auto-restarts the node, watch how the node once again becomes healthy.
3. Back in the terminal, verify that the pod was automatically restarted: `$ kubectl get pod cockroachdb-2 ``NAME READY STATUS RESTARTS AGE cockroachdb-2 1/1 Running 0 12s `

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl get pod cockroachdb-2
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   NAME            READY     STATUS    RESTARTS   AGE
   cockroachdb-2   1/1       Running   0          12s
   ```

## Step 6. Stop the cluster

This procedure shuts down the CockroachDB cluster and deletes the resources you just created, including the logs. This command intentionally does **not** delete the persistent volumes that were attached to the pods or any secrets you may have created. Before deleting a cluster's persistent volumes, be sure to back them up. For more information, refer to [Delete a Cluster's Persistent Volumes](#delete-a-cluster’s-persistent-volumes) and [Managing Secrets Using `kubectl`](https://kubernetes.io/docs/tasks/configmap-secret/managing-secret-using-kubectl) in the Kubernetes project's documentation.

<Danger>
  Do **not** use the `--all` flag to `kubectl delete`, to avoid the risk of unintentional data loss.
</Danger>

This command is very long; you may need to scroll your browser to read all of it.

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
kubectl delete \
  pods,statefulsets,services,poddisruptionbudget,jobs,rolebinding,clusterrolebinding,role,clusterrole,serviceaccount,alertmanager,prometheus,prometheusrule,serviceMonitor \
  -l app=cockroachdb
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
pod "cockroachdb-0" deleted
pod "cockroachdb-1" deleted
pod "cockroachdb-2" deleted
pod "cockroachdb-3" deleted
service "alertmanager-cockroachdb" deleted
service "cockroachdb" deleted
service "cockroachdb-public" deleted
poddisruptionbudget "cockroachdb-budget" deleted
job "cluster-init" deleted
clusterrolebinding "prometheus" deleted
clusterrole "prometheus" deleted
serviceaccount "prometheus" deleted
alertmanager "cockroachdb" deleted
prometheus "cockroachdb" deleted
prometheusrule "prometheus-cockroachdb-rules" deleted
servicemonitor "cockroachdb" deleted
```

1. [Install the Helm client](https://helm.sh/docs/intro/install) (version 3.0 or higher) and add the `cockroachdb` chart repository:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ helm repo add cockroachdb https://charts.cockroachdb.com/
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   "cockroachdb" has been added to your repositories
   ```
2. Update your Helm chart repositories to ensure that you're using the [latest CockroachDB chart](https://github.com/cockroachdb/helm-charts/blob/master/cockroachdb/Chart.yaml):

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ helm repo update
   ```
3. Modify our Helm chart's [`values.yaml`](https://github.com/cockroachdb/helm-charts/blob/master/cockroachdb/values.yaml) parameters for your deployment scenario.

   Create a `my-values.yaml` file to override the defaults in `values.yaml`, substituting your own values in this example based on the guidelines below.

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   statefulset:
     resources:
       limits:
         memory: "8Gi"
       requests:
         memory: "8Gi"
   conf:
     cache: "2Gi"
     max-sql-memory: "2Gi"
   ```

   1. 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.cache` and `conf.max-sql-memory` each to 1/4 of the `memory` allocation specified in `statefulset.resources.requests` and `statefulset.resources.limits`.

<Tip>
  For example, if you are allocating 8Gi of `memory` to each CockroachDB node, allocate 2Gi to `cache` and 2Gi to `max-sql-memory`.
</Tip>

4. For an insecure deployment, set `tls.enabled` to `false`. For clarity, this example includes the example configuration from the previous steps.

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   statefulset:
     resources:
       limits:
         memory: "8Gi"
       requests:
         memory: "8Gi"
   conf:
     cache: "2Gi"
     max-sql-memory: "2Gi"
   tls:
     enabled: false
   ```

   1. You may want to modify `storage.persistentVolume.size` and `storage.persistentVolume.storageClass` for your use case. This chart defaults to 100Gi of disk space per pod. For more details on customizing disks for performance, see <InternalLink path="kubernetes-performance#disk-type">these instructions</InternalLink>.

<Note>
  If necessary, you can <InternalLink path="configure-cockroachdb-kubernetes?filters=helm#expand-disk-size">expand disk size</InternalLink> after the cluster is live.
</Note>

5. Install the CockroachDB Helm chart.

   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`.

<Note>
  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.
</Note>

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ helm install my-release --values my-values.yaml cockroachdb/cockroachdb
```

Behind the scenes, this command uses our `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.

6. Confirm that CockroachDB cluster initialization has completed successfully, with the pods for CockroachDB showing `1/1` under `READY` and the pod for initialization showing `COMPLETED` under `STATUS`:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl get pods
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   NAME                                READY     STATUS      RESTARTS   AGE
   my-release-cockroachdb-0            1/1       Running     0          8m
   my-release-cockroachdb-1            1/1       Running     0          8m
   my-release-cockroachdb-2            1/1       Running     0          8m
   my-release-cockroachdb-init-hxzsc   0/1       Completed   0          1h
   ```
7. Confirm that the persistent volumes and corresponding claims were created successfully for all three pods:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl get pv
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM                                      STORAGECLASS   REASON    AGE
   pvc-71019b3a-fc67-11e8-a606-080027ba45e5   100Gi      RWO            Delete           Bound     default/datadir-my-release-cockroachdb-0   standard                 11m
   pvc-7108e172-fc67-11e8-a606-080027ba45e5   100Gi      RWO            Delete           Bound     default/datadir-my-release-cockroachdb-1   standard                 11m
   pvc-710dcb66-fc67-11e8-a606-080027ba45e5   100Gi      RWO            Delete           Bound     default/datadir-my-release-cockroachdb-2   standard                 11m
   ```

The StatefulSet configuration sets all CockroachDB nodes to log to `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

1. Launch a temporary interactive pod and start the <InternalLink path="cockroach-sql">built-in SQL client</InternalLink> inside it:

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl run cockroachdb -it \
   --image=cockroachdb/cockroach:v25.2.15 \
   --rm \
   --restart=Never \
   -- sql \
   --insecure \
   --host=my-release-cockroachdb-public
   ```
2. Run some basic <InternalLink path="learn-cockroachdb-sql">CockroachDB SQL statements</InternalLink>:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > CREATE DATABASE bank;
   ```

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > CREATE TABLE bank.accounts (
       id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
         balance DECIMAL
     );
   ```

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > INSERT INTO bank.accounts (balance)
     VALUES
         (1000.50), (20000), (380), (500), (55000);
   ```

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > SELECT * FROM bank.accounts;
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
                      id                  | balance
   +--------------------------------------+---------+
     6f123370-c48c-41ff-b384-2c185590af2b |     380
     990c9148-1ea0-4861-9da7-fd0e65b0a7da | 1000.50
     ac31c671-40bf-4a7b-8bee-452cff8a4026 |     500
     d58afd93-5be9-42ba-b2e2-dc00dcedf409 |   20000
     e6d8f696-87f5-4d3c-a377-8e152fdc27f7 |   55000
   (5 rows)
   ```
3. Exit the SQL shell and delete the temporary pod:

   ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   > \q
   ```

## Step 4. Access the DB Console

To access the cluster's <InternalLink path="ui-overview">DB Console</InternalLink>:

1. In a new terminal window, port-forward from your local machine to the `cockroachdb-public` service: `$ kubectl port-forward service/cockroachdb-public 8080 `

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl port-forward service/my-release-cockroachdb-public 8080
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   Forwarding from 127.0.0.1:8080 -> 8080
   ```

   The `port-forward` command must be run 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 configuring `kubectl` locally and running the above `port-forward` command on your local machine.

2. Go to [http://localhost:8080](http://localhost:8080/).

3. In the UI, verify that the cluster is running as expected:
   * View the <InternalLink path="ui-cluster-overview-page#node-list">Node List</InternalLink> to ensure that all nodes successfully joined the cluster.
   * Click the **Databases** tab on the left to verify that `bank` is listed.

## Step 5. Simulate node failure

Based on the `replicas: 3` line in the StatefulSet configuration, Kubernetes ensures that three pods/nodes are running at all times. When a pod/node fails, Kubernetes automatically creates another pod/node with the same network identity and persistent storage.

To see this in action:

1. Terminate one of the CockroachDB nodes: `$ kubectl delete pod cockroachdb-2 ``pod "cockroachdb-2" deleted `

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl delete pod my-release-cockroachdb-2
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   pod "my-release-cockroachdb-2" deleted
   ```
2. In the DB Console, the **Cluster Overview** will soon show one node as **Suspect**. As Kubernetes auto-restarts the node, watch how the node once again becomes healthy.
3. Back in the terminal, verify that the pod was automatically restarted: `$ kubectl get pod cockroachdb-2 ``NAME READY STATUS RESTARTS AGE cockroachdb-2 1/1 Running 0 12s `

   ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   $ kubectl get pod my-release-cockroachdb-2
   ```

   ```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
   NAME                       READY     STATUS    RESTARTS   AGE
   my-release-cockroachdb-2   1/1       Running   0          44s
   ```

## Step 6. Stop the cluster

This procedure shuts down the CockroachDB cluster and deletes the resources you just created, including the logs. This command intentionally does **not** delete the persistent volumes that were attached to the pods or any secrets you may have created. Before deleting a cluster's persistent volumes, be sure to back them up. For more information, refer to [Delete a Cluster's Persistent Volumes](#delete-a-cluster’s-persistent-volumes) and [Managing Secrets Using `kubectl`](https://kubernetes.io/docs/tasks/configmap-secret/managing-secret-using-kubectl) in the Kubernetes project's documentation.

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
$ helm uninstall my-release
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
release "my-release" deleted
```

### Delete a cluster's persistent volumes

If you need to free up the storage used by CockroachDB, you can optionally delete the persistent volumes that were attached to the pods, after first backing up your data.

<Danger>
  Before you delete a cluster's 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](https://kubernetes.io/docs/tasks/run-application/delete-stateful-set#persistent-volumes).
</Danger>

Refer to the Kubernetes project's documentation for more information and recommendations.

### Stop Kubernetes

To delete the Kubernetes cluster:

* Hosted GKE:

  ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  $ gcloud container clusters delete cockroachdb
  ```
* Hosted EKS:

  ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  $ eksctl delete cluster --name cockroachdb
  ```
* Manual GCE:

  ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  $ cluster/kube-down.sh
  ```
* Manual AWS:

  ```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  $ cluster/kube-down.sh
  ```

## See also

* <InternalLink path="kubernetes-overview">Kubernetes Overview</InternalLink>
* <InternalLink path="deploy-cockroachdb-with-kubernetes">Deploy CockroachDB on Kubernetes</InternalLink>
* <InternalLink path="monitor-cockroachdb-kubernetes">Cluster monitoring</InternalLink>
* <InternalLink path="orchestrate-cockroachdb-with-kubernetes-multi-cluster">Kubernetes Multi-Cluster Deployment</InternalLink>
* <InternalLink path="kubernetes-performance">Kubernetes Performance Guide</InternalLink>
* <InternalLink path="recommended-production-settings">Production Checklist</InternalLink>
