The documentation you are viewing is for Dapr v1.8 which is an older version of Dapr. For up-to-date documentation, see the latest version.
CockroachDB
Create a Dapr component
Create a file called cockroachdb.yaml
, paste the following and replace the <CONNECTION STRING>
value with your connection string. The connection string for CockroachDB follow the same standard for PostgreSQL connection string. For example, "host=localhost user=root port=26257 connect_timeout=10 database=dapr_test"
. See the CockroachDB documentation on database connections for information on how to define a connection string.
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: <NAME>
spec:
type: state.cockroachdb
version: v1
metadata:
- name: connectionString
value: "<CONNECTION STRING>"
Spec metadata fields
Field | Required | Details | Example |
---|---|---|---|
connectionString | Y | The connection string for CockroachDB | "host=localhost user=root port=26257 connect_timeout=10 database=dapr_test" |
actorStateStore | N | Consider this state store for actors. Defaults to "false" |
"true" , "false" |
Setup CockroachDB
-
Run an instance of CockroachDB. You can run a local instance of CockroachDB in Docker CE with the following command:
This example does not describe a production configuration because it sets a single-node cluster, it’s only recommend for local environment.
docker run --name roach1 -p 26257:26257 cockroachdb/cockroach:v21.2.3 start-single-node --insecure
-
Create a database for state data.
To create a new database in CockroachDB, run the following SQL command inside container:
docker exec -it roach1 ./cockroach sql --insecure -e 'create database dapr_test'
The easiest way to install CockroachDB on Kubernetes is by using the CockroachDB Operator:
Related links
- Basic schema for a Dapr component
- Read this guide for instructions on configuring state store components
- State management building block
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.