cockroachdb
CockroachDB is a scalable, survivable, strongly-consistent SQL database.
About this chart
CockroachDB Helm Chart (Legacy)
⚠️ Deprecation notice
This is the legacy CockroachDB Helm chart (the StatefulSet-based chart). It is deprecated and no longer receives new features. For new deployments, install the CockroachDB Operator and CockroachDB charts as separate releases. See the installation guide.
See the official Kubernetes deployment deprecation notice for the full timeline and migration guidance.
Migration paths:
- Automatic (recommended): docs/migration/helm/controller_migration.md
- Manual: docs/migration/helm/manual_migration.md
CockroachDB - the open source, cloud-native distributed SQL database.
Documentation
Below is a brief overview of operating the CockroachDB Helm Chart and some specific implementation details. For additional information on deploying CockroachDB, please see:
https://www.cockroachlabs.com/docs/stable/orchestrate-cockroachdb-with-kubernetes.html
Note that the documentation requires Helm 3.0 or higher.
Prerequisites Details
- Kubernetes 1.8
- PV support on the underlying infrastructure (only if using
storage.persistentVolume). Docker for windows hostpath provisioner is not supported. - If you want to secure your cluster to use TLS certificates for all network communication, Helm must be installed with RBAC privileges or else you will get an "attempt to grant extra privileges" error.
StatefulSet Details
StatefulSet Caveats
Chart Details
This chart will do the following:
- Set up a dynamically scalable CockroachDB cluster using a Kubernetes StatefulSet.
Add the CockroachDB Repository
$ helm repo add cockroachdb https://charts.cockroachdb.com/
Installing the Chart
To install the chart with the release name my-release:
$ helm install my-release cockroachdb/cockroachdb
Note that for a production cluster, you will likely want to override the following parameters in values.yaml with your own values.
statefulset.resources.requests.memoryandstatefulset.resources.limits.memoryallocate memory resources to CockroachDB pods in your cluster.conf.cacheandconf.max-sql-memoryare memory limits that we recommend setting to 1/4 of the above resource allocation. When running CockroachDB, you must set these limits explicitly to avoid running out of memory.storage.persistentVolume.sizedefaults to100Giof disk space per pod, which you may increase or decrease for your use case.storage.persistentVolume.storageClassuses the default storage class for your environment. We strongly recommend that you specify a storage class which uses an SSD.tls.enabledmust be set toyes/trueto deploy in secure mode.
For more information on overriding the values.yaml parameters, please see:
Confirm that all pods are Running successfully and init has been completed:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-release-cockroachdb-0 1/1 Running 0 1m
my-release-cockroachdb-1 1/1 Running 0 1m
my-release-cockroachdb-2 1/1 Running 0 1m
my-release-cockroachdb-init-k6jcr 0/1 Completed 0 1m
Confirm that persistent volumes are created and claimed for each pod:
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pvc-64878ebf-f3f0-11e8-ab5b-42010a8e0035 100Gi RWO Delete Bound default/datadir-my-release-cockroachdb-0 standard 51s
pvc-64945b4f-f3f0-11e8-ab5b-42010a8e0035 100Gi RWO Delete Bound default/datadir-my-release-cockroachdb-1 standard 51s
pvc-649d920d-f3f0-11e8-ab5b-42010a8e0035 100Gi RWO Delete Bound default/datadir-my-release-cockroachdb-2 standard 51s
Running in secure mode
In order to set up a secure cockroachdb cluster set tls.enabled to yes/true
There are 3 ways to configure a secure cluster, with this chart. This all relates to how the certificates are issued:
- Self-signer (default)
- Cert-manager
- Manual
Self-signer
For instructions on using self-signer to provision certificates for the statefulset-based Helm chart, see the Installation of statefulset-based Helm Chart with self-signer section in the documentation.
Additional Subject Alternative Names (SANs) for Load Balancers
When using the self-signer, you can include additional Subject Alternative Names (SANs) in node certificates. This is useful when:
- Routing traffic through load balancers with
sslmode=verify-full - Setting up Physical Cluster Replication (PCR) through external endpoints
- Accessing the cluster through custom DNS names or IP addresses
To add custom SANs, configure tls.certs.selfSigner.additionalSANs:
tls:
enabled: true
certs:
selfSigner:
enabled: true
additionalSANs:
- "my-loadbalancer.example.com"
- "192.168.1.100"
- "external-endpoint.domain.com"
Or using Helm command-line options:
$ helm install my-release cockroachdb/cockroachdb \
--set tls.enabled=true \
--set tls.certs.selfSigner.enabled=true \
--set 'tls.certs.selfSigner.additionalSANs[0]=my-loadbalancer.example.com' \
--set 'tls.certs.selfSigner.additionalSANs[1]=192.168.1.100'
Note: The additional SANs are automatically included in both initial certificate generation and subsequent certificate rotations.
Manual
If you wish to supply the certificates to the nodes yourself set tls.certs.provided to yes/true. You may want to use this if you want to use a different certificate authority from the one being used by Kubernetes or if your Kubernetes cluster doesn't fully support certificate-signing requests. To use this, first set up your certificates and load them into your Kubernetes cluster as Secrets using the commands below:
$ mkdir certs
$ mkdir my-safe-directory
$ cockroach cert create-ca --certs-dir=certs --ca-key=my-safe-directory/ca.key
$ cockroach cert create-client root --certs-dir=certs --ca-key=my-safe-directory/ca.key
$ kubectl create secret generic cockroachdb-root --from-file=certs
secret/cockroachdb-root created
$ cockroach cert create-node --certs-dir=certs --ca-key=my-safe-directory/ca.key localhost 127.0.0.1 my-release-cockroachdb-public my-release-cockroachdb-public.my-namespace my-release-cockroachdb-public.my-namespace.svc.cluster.local *.my-release-cockroachdb *.my-release-cockroachdb.my-namespace *.my-release-cockroachdb.my-namespace.svc.cluster.local
$ kubectl create secret generic cockroachdb-node --from-file=certs
secret/cockroachdb-node created
Note: The subject alternative names are based on a release called
my-releasein themy-namespacenamespace. Make sure they match the services created with the release duringhelm install
If your certificates are stored in tls secrets such as secrets generated by cert-manager, the secret will contain files named:
ca.crttls.crttls.key
Cockroachdb, however, expects the files to be named like this:
ca.crtnode.crtnode.keyclient.root.crtclient.root.key
By enabling tls.certs.tlsSecret the tls secrets are projected on to the correct filenames, when they are mounted to the cockroachdb pods.
Cert-manager
For instructions on using cert-manager to provision certificates for the statefulset-based Helm chart, see the Installation of statefulset-based Helm Chart with Cert Manager section in the documentation.
Additional Subject Alternative Names (SANs)
To add custom DNS names or IP addresses to the cert-manager issued node certificate, set
tls.certs.certManagerIssuer.additionalDnsNames and
tls.certs.certManagerIssuer.additionalIpAddresses:
tls:
enabled: true
certs:
selfSigner:
enabled: false
certManager: true
certManagerIssuer:
additionalDnsNames:
- "my-domain.example.com"
- "*.my-domain.example.com"
additionalIpAddresses:
- "10.0.0.10"
See Additional SANs on the node certificate for details, including how certificate changes are picked up by running pods.
Zero-downtime certificate rotation
The chart supports zero-downtime certificate rotation using SIGHUP signal when tls.enableSighupRotation is set to true. This allows you to rotate TLS certificates without restarting CockroachDB pods.
Important: Zero-downtime SIGHUP-based rotation is only supported with externally managed certificates (user-provided or cert-manager) where the user controls the rotation and signaling process. It is not compatible with self-signed certificates (tls.certs.selfSigner.enabled=true), as the self-signer handles rotation by triggering pod restarts.
How it works:
When enableSighupRotation is enabled:
- Node certificates (ca.crt, node.crt, node.key) are mounted directly from Kubernetes secrets (no copy-certs initContainer)
- Certificate files have 0440 permissions (owner+group read) instead of 0400. This is required because with the chart's default pod
fsGroup: 1000(set viasecurityContext.enabled=true), Kubernetes mounts secrets withroot:1000ownership, and the CockroachDB process (running as user 1000) needs group read access. If you disable or override the pod securityContext, ensure the mounted secret file ownership/permissions still allow CockroachDB to read the certificates. - After updating the certificate secrets in Kubernetes, send SIGHUP signal to CockroachDB processes to reload certificates
Example usage:
# Deploy with SIGHUP rotation enabled
$ helm install my-release cockroachdb/cockroachdb \
--set tls.enabled=true \
--set tls.enableSighupRotation=true \
--set tls.certs.provided=true \
--set tls.certs.tlsSecret=true
To rotate certificates:
- Update the certificate secrets:
$ kubectl create secret generic cockroachdb-node \
--from-file=ca.crt=new-ca.crt \
--from-file=tls.crt=new-node.crt \
--from-file=tls.key=new-node.key \
--namespace=<your-namespace> \
--dry-run=client -o yaml | kubectl apply -f -
-
Wait for kubelet to sync the updated certificates to pods (30-60 seconds)
-
Send SIGHUP signal to reload certificates without restarting:
$ for i in 0 1 2; do
kubectl exec my-release-cockroachdb-$i -- sh -c "kill -1 1"
sleep 5
done
Note: When enableSighupRotation is disabled (default), certificates are copied by an initContainer with strict 0400 permissions, and pod restarts are required for certificate rotation.
Upgrading the cluster
Chart version 3.0.0 and after
Launch a temporary interactive pod and start the built-in SQL client:
$ kubectl run cockroachdb --rm -it \
--image=cockroachdb/cockroach \
--restart=Never \
-- sql --insecure --host=my-release-cockroachdb-public
If you are running in secure mode, you will have to provide a client certificate to the cluster in order to authenticate, so the above command will not work. See here for an example of how to set up an interactive SQL shell against a secure cluster or here for an example application connecting to a secure cluster.
Set cluster.preserve_downgrade_option, where $current_version is the CockroachDB version currently running (e.g., 19.2):
> SET CLUSTER SETTING cluster.preserve_downgrade_option = '$current_version';
Exit the shell and delete the temporary pod:
> \q
Kick off the upgrade process by changing the new Docker image, where $new_version is the CockroachDB version to which you are upgrading:
$ helm upgrade my-release cockroachdb/cockroachdb \
--set image.tag=$new_version \
--reuse-values
Kubernetes will carry out a safe rolling upgrade of your CockroachDB nodes one-by-one.
However, the upgrade will fail if it involves adding new Persistent Volume Claim (PVC) to the existing pods (e.g. enabling WAL Failover, pushing logs to a separate volume, etc.).
In such cases, kindly run the scripts/upgrade_with_new_pvc.sh script to upgrade the cluster.
./scripts/upgrade_with_new_pvc.sh -h can be used for generating help on how to run the script.
Monitor the cluster's pods until all have been successfully restarted:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-release-cockroachdb-0 1/1 Running 0
Deploy cockroachdb with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has cockroachdb on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartcockroachdb is pinned at v23.0.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply