Overview
CockroachDB is a distributed SQL database that provides automatic replication, horizontal scalability, and built-in fault tolerance across multiple regions. This template deploys a multi-region CockroachDB cluster on Control Plane as a stateful workload with replica-direct load balancing. Each location runs a configurable number of replicas that discover and join one another using Control Plane’s internal DNS. On first deployment, the cluster initializes itself, creates a database and user, registers all regions, and sets the survival goal toSURVIVE REGION FAILURE.
What Gets Created
- GVC — A dedicated GVC across the specified locations.
- Stateful CockroachDB Workload — CockroachDB (
v25.4.0) with per-location replica scaling and replica-direct load balancing. - Volume Set — Persistent ext4 storage (general-purpose-ssd) with final snapshot creation and 7-day retention.
- Identity & Policy — An identity bound to the workload with
revealaccess to the startup and user secrets, and cloud storage access when backup is enabled. - Secrets — A startup script for cluster join/initialization and an opaque secret for the database user credential.
- Backup Cron Workload (optional) — A scheduled job that triggers a CockroachDB
BACKUPSQL command to stream data directly to AWS S3 or GCS.
Architecture
CockroachDB uses the Raft consensus protocol to replicate data across nodes. Each Control Plane location maps to a CockroachDB locality region, and replicas advertise their address via internal DNS (replica-N.WORKLOAD.LOCATION.GVC.cpln.local).
With 3 or more regions and the SURVIVE REGION FAILURE survival goal, the cluster tolerates the complete loss of one region without impacting availability.
Installation
This template has no external prerequisites unless backup is enabled. To install, follow the instructions for your preferred method:UI
Browse, install, and manage templates visually
CLI
Manage templates from your terminal
Terraform
Declare templates in your Terraform configurations
Pulumi
Declare templates in your Pulumi programs
Configuration
The defaultvalues.yaml for this template:
Locations and Replicas
Configure thegvc.locations section to control which regions the cluster spans and how many replicas run in each.
While CockroachDB can run on 2 locations, a minimum of 3 locations with 3 replicas per location is recommended. This is the minimum required for CockroachDB to survive a full region failure.
replicas to 0 suspends the workload in that location without removing it from the configuration.
Database Initialization
Thedatabase section specifies a database and user to create automatically when the cluster first initializes:
These values are only applied on the first initialization. If the cluster has already been initialized, they are skipped on restart or upgrade. To change credentials or the database name on an existing cluster, use CockroachDB’s native commands (e.g.
ALTER USER, RENAME DATABASE).Resources and Storage
resources.cpuandresources.memoryset the CPU and memory allocated to each CockroachDB replica.volumeset.capacitysets the initial persistent volume size in GiB (minimum 10).volumeset.autoscaling.enabled— Enable automatic volume expansion as data grows.volumeset.autoscaling.maxCapacity— Maximum volume size in GiB.volumeset.autoscaling.minFreePercentage— Triggers a scale-up when free space falls below this percentage.volumeset.autoscaling.scalingFactor— Multiplier applied to the current capacity on each scale-up.
Internal Access
Theinternal_access section controls which workloads can reach the CockroachDB cluster internally:
| Type | Description |
|---|---|
same-gvc | Allow access from all workloads in the same GVC |
same-org | Allow access from all workloads in the same organization |
workload-list | Allow access only from specific workloads listed in workloads (can be combined with same-gvc) |
workload-list, specify each workload using its full link format:
Connecting to CockroachDB
Once deployed, the SQL interface is available on port 26257. Connect from a workload within the same GVC using:This template deploys CockroachDB in insecure mode (no TLS). It is intended for internal workloads that connect through Control Plane’s internal network.
http://localhost:8080 in your browser.
This template creates a GVC with a default name defined in the values file. If you plan to deploy multiple instances, you must assign a unique GVC name for each deployment.
Backup
Backup is disabled by default. When enabled, a cron workload triggers a CockroachDBBACKUP SQL command on the configured schedule. CockroachDB nodes stream backup data directly to cloud storage using their own workload identity — the backup job only issues the SQL command and does not transfer data itself.
backup.enabled— Enable scheduled backups.backup.schedule— Cron expression for backup frequency (default: daily at 2am UTC).backup.provider—awsorgcp.backup.location— The Control Plane location where the backup cron job runs. Set this to the region closest to your storage bucket to minimize cross-region transfer latency.backup.activeDeadlineSeconds— Hard timeout for the backup job in seconds (default:14400/ 4 hours). The job is killed if it exceeds this limit.backup.resources.cpu/backup.resources.memory— Resources for the backup cron container.
AWS S3
Before enabling backup withprovider: aws, complete the following in your AWS account:
- Create an S3 bucket. Set
backup.aws.bucketto its name andbackup.aws.regionto its region. - If you do not have a Cloud Account set up, refer to the docs to Create a Cloud Account. Set
backup.aws.cloudAccountNameto its name. - Create an IAM policy with the following JSON, replacing
YOUR_BUCKET_NAME:
- Set
backup.aws.policyNameto the name of the policy created in step 3. - Set
backup.aws.prefixto the folder path where backups will be stored.
GCS
Before enabling backup withprovider: gcp, complete the following in your GCP account:
- Create a GCS bucket. Set
backup.gcp.bucketto its name. - If you do not have a Cloud Account set up, refer to the docs to Create a Cloud Account. Set
backup.gcp.cloudAccountNameto its name. - Add the Storage Admin role to the GCP service account associated with the Cloud Account.
- Set
backup.gcp.prefixto the folder path where backups will be stored.
Restoring a Backup
Backups are stored atBUCKET/PREFIX/. Run cockroach sql from a machine with network access to the cluster.
AWS S3
External References
CockroachDB Documentation
Official CockroachDB documentation
Multi-Region Overview
Learn about multi-region deployments
Survive Region Failure
Configure region failure survival goals
Backup Image Source
Source code for the CockroachDB backup container image
CockroachDB Template
View the source files, default values, and chart definition