cockroachdb-chart
CockroachDB is a scalable, survivable, strongly-consistent SQL database.
About this chart
CockroachDB Helm Chart
CockroachDB - the open source, cloud-native distributed SQL database.
This is a subchart for installing the CockroachDB cluster.
See the installation overview for published charts and installation order.
Running in secure mode
In order to set up a secure cockroachdb cluster set cockroachdb.tls.enabled to 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)
- Manual
- Cert-manager
Self-signer
See the Installation of CockroachDB Operator with Self-Signed Certificates section in the documentation.
Manual
If you wish to supply the certificates to the nodes yourself set cockroachdb.tls.externalCertificates.enabled to 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
Cert-manager
See the Installation of CockroachDB Operator with Cert Manager section in the documentation.
CockroachDB Helm Chart
CockroachDB - the cloud-native distributed SQL database.
Below is a brief overview of operating the CockroachDB Helm Chart(v2) with Operator.
Prerequisites
- Kubernetes 1.30 or higher; see the Kubernetes compatibility matrix for tested versions.
- Helm 3.0 or higher
- Create a namespace to perform the operations against. In this case, we are using
cockroach-nsnamespace. - If you want to secure your cluster to use TLS certificates for all network communications, Helm must be installed with RBAC privileges or else you will get an "attempt to grant extra privileges" error.
Set the environment variables:
export CRDBOPERATOR=crdb-operator
export CRDBCLUSTER=cockroachdb
export NAMESPACE=cockroach-ns
Notes
All the Helm commands below use the local chart folders after checking out this repository. You can also use the published charts listed in the installation overview. Install the operator and CockroachDB charts as separate releases (installing the umbrella chart directly is unsupported).
Installation
Install Operator
- Update
cloudRegionaccordingly inoperator/values.yaml. This value must be same as the current region provided under regions section atcockroachdb/values.yaml.
cloudRegion: us-central1
$ helm install $CRDBOPERATOR ./cockroachdb-operator/charts/operator -n $NAMESPACE
Install CockroachDB
- Modify the
regionsconfiguration ofcockroachdb/values.yaml. The defaultregionsconfiguration uses k3d, so update it as per your cloud provider (e.g.gcp,aws, etc.)
cockroachdb:
crdbCluster:
regions:
- code: us-central1
nodes: 3
cloudProvider: gcp
namespace: cockroach-ns
- If the
cloudProviderisazure, create an application in your Azure tenant and create a secret namedazure-cluster-identity-credentials-secretwhich containsazure_client_idandazure_client_secretto hold the application credentials.[2] - Modify the other relevant configuration like
topologySpreadConstraints,localityLabels,service.ports, as required.
Topology spread constraints with operators before v1.1.0
Chart releases before cockroachdb-parent-25.3.4-preview+1 already render topology spread
constraints from the first-class cockroachdb.crdbCluster.topologySpreadConstraints value, so no
compatibility action is required.
Starting with cockroachdb-parent-25.3.4-preview+1, the chart removed the first-class field from
cockroachdb-parent/charts/cockroachdb/values.yaml and
cockroachdb-parent/charts/cockroachdb/templates/crdb.yaml in favor of podTemplate. However,
operator versions earlier than v1.1.0 still require the first-class
spec.template.spec.topologySpreadConstraints field for topology-aware scale-down.
When using one of these chart releases with an operator earlier than v1.1.0, ensure the
first-class field remains on the CrdbCluster through every Helm install or upgrade. The default
chart does not restore the deprecated field. Users who maintain a local copy of the chart can
temporarily add it back to both files. Add the value to values.yaml:
cockroachdb:
crdbCluster:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
Add this rendering block under spec.template.spec in templates/crdb.yaml:
{{- with .Values.cockroachdb.crdbCluster.topologySpreadConstraints }}
topologySpreadConstraints: {{- toYaml . | nindent 8 }}
{{- end }}
Moving the constraints to podTemplate is not required before upgrading the operator. If
podTemplate.spec.topologySpreadConstraints is already configured, or is configured during this
period, keep the same constraints in both fields. After every operator managing the cluster is on
v1.1.0, remove the temporary first-class value and rendering block; keep the podTemplate value
if it is in use.
Install the cockroachdb chart:
$ helm install $CRDBCLUSTER ./cockroachdb-operator/charts/cockroachdb -n $NAMESPACE
You can Override the default parameters using the --set key=value[,key=value] argument while installing the chart.
helm install $CRDBCLUSTER ./cockroachdb-operator/charts/cockroachdb --set clusterDomain=cluster-test.local -n $NAMESPACE
Alternatively, a YAML file that specifies custom values for the parameters can be provided while installing the chart. For example:
$ helm install $CRDBCLUSTER ./cockroachdb-operator/charts/cockroachdb -f my-values.yaml -n $NAMESPACE
Post-Init SQL
cockroachdb.crdbCluster.postInitSQL sets spec.postInitSQL on the CrdbCluster
resource. The operator runs these SQL sources once after cluster initialization.
TLS must be enabled, and the CrdbCluster must reconcile in MutableOnly mode.
cockroachdb:
crdbCluster:
postInitSQL:
secretRef:
name: license-sql
key: license.sql
configMapRef:
name: bootstrap-sql
key: init.sql
inline:
- "CREATE DATABASE IF NOT EXISTS myapp"
- "CREATE USER IF NOT EXISTS app_user"
secretRef, configMapRef, and inline are optional and run in that order.
Failures are reported on the PostInitSQLApplied condition. Keep statements idempotent
because a retry starts from the first statement.
Operator Feature Gates
cockroachdb.crdbCluster.features sets spec.features on the CrdbCluster. Preserve existing
entries when adding operator feature gates such as recovery overrides:
cockroachdb:
crdbCluster:
features:
- skip-under-replicated-ranges-check
Multi Region Deployments
For multi-region cluster deployments, ensure the required networking is setup which allows for service discovery across regions. Also, ensure that the same CA cert is used across all the regions.
For each region, modify the regions configuration of cockroachdb/values.yaml and perform helm install as above against the respective Kubernetes cluster.
While applying helm install in a given region:
- Verify that the domain matches the
clusterDomainincockroachdb/values.yamlfor the corresponding region. - Ensure
regionscaptures the information for regions that have already been deployed, including the current region. This enables CockroachDB in the current region to connect to CockroachDB deployed in the existing regions.
For example, if us-central1 has already been deployed, and us-east1 is being deployed to:
cockroachdb:
clusterDomain: cluster.gke.gcp-us-east1
crdbCluster:
regions:
- code: us-central1
nodes: 3
cloudProvider: gcp
domain: cluster.gke.gcp-us-central1
namespace: cockroach-ns
- code: us-east1
nodes: 3
cloudProvider: gcp
domain: cluster.gke.gcp-us-east1
namespace: cockroach-ns
Upgrade CockroachDB cluster
Modify the required configuration in cockroachdb/values.yaml and perform an upgrade through Helm:
$ helm upgrade --reuse-values $CRDBCLUSTER ./cockroachdb-operator/charts/cockroachdb --values ./cockroachdb-operator/charts/cockroachdb/values.yaml -n $NAMESPACE
Helm 4 server-side apply
Helm 4 uses server-side apply (SSA) by default for releases first installed with Helm 4. Releases upgraded from Helm 3 normally continue using client-side apply because Helm records the apply method. SSA can still be enabled explicitly or used after a release is recreated or imported.
The default Helm 4 workflow does not require special handling: install the
chart, make CrdbCluster changes through chart values, and use the normal
helm upgrade command. Avoid manually editing the Helm-managed CrdbCluster
with kubectl edit, kubectl apply, or another tool. A manual change can cause
another field manager to claim the affected field, and a later Helm 4 upgrade
can then report an SSA ownership conflict instead of overwriting it.
If an upgrade reports a conflict, first inspect the reported fields and the
resource's managedFields. Move any desired manual changes into the chart
values, reconcile or revert the out-of-band change, and retry the normal
upgrade. If you have reviewed the conflicting fields and intentionally want
Helm to reclaim their ownership, run:
$ helm upgrade --server-side=true --force-conflicts --reuse-values $CRDBCLUSTER ./cockroachdb-operator/charts/cockroachdb --values ./cockroachdb-operator/charts/cockroachdb/values.yaml -n $NAMESPACE
--force-conflicts transfers ownership of conflicting fields, so do not use it
without reviewing the affected resource. Helm 4's --force-replace flag
(formerly --force) replaces resources and is not the remedy for an SSA
ownership conflict. See the Helm 4 server-side apply
overview and
HIP-0023.
Migration
This chart can be adopted after a cluster has been migrated to the CockroachDB Operator.
The supported migration paths are:
- Legacy Operator
v1alpha1CrdbClusterto CockroachDB Operatorv1beta1CrdbCluster - StatefulSet based Helm deployment to CockroachDB Operator
v1beta1CrdbCluster
This is different from the older CockroachDB Operator API transition where existing
CockroachDB Operator users moved from the Operator's own v1alpha1 API to v1beta1.
For the migration steps, use the dedicated guides:
- Automatic migration from Legacy Operator to CockroachDB Operator: docs/migration/operator/controller_migration.md
- Automatic migration from StatefulSet to CockroachDB Operator: docs/migration/helm/controller_migration.md
- Manual migration guides: docs/migration/operator/manual_migration.md and docs/migration/helm/manual_migration.md
For chart adoption after migration:
- Legacy Operator or Helm StatefulSet migration users should follow the controller migration guides before adopting this chart.
- After migration is complete, verify the migrated cluster is readable through the
v1beta1API:kubectl get crdbclusters.v1beta1.crdb.cockroachlabs.com <cluster-name> -n <namespace>. - Generate a values file from the live migrated resources before adopting this chart with Helm:
Deploy cockroachdb-chart with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has cockroachdb-chart 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-chart is pinned at v26.4.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