Cassandra

Detailed information on the Cassandra state store component

Create a Cassandra state store

You can run Cassandra locally with the Datastax Docker image:

  1. docker run -e DS_LICENSE=accept --memory 4g --name my-dse -d datastax/dse-server -g -s -k

You can then interact with the server using localhost:9042.

The easiest way to install Cassandra on Kubernetes is by using the Helm chart:

  1. kubectl create namespace cassandra
  2. helm install cassandra incubator/cassandra --namespace cassandra

This will install Cassandra into the cassandra namespace by default. To interact with Cassandra, find the service with: kubectl get svc -n cassandra.

For example, if installing using the example above, the Cassandra DNS would be:

cassandra.cassandra.svc.cluster.local

Create a Dapr component

The next step is to create a Dapr component for Cassandra.

Create the following YAML file named cassandra.yaml:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: state.cassandra
  8. version: v1
  9. metadata:
  10. - name: hosts
  11. value: <REPLACE-WITH-COMMA-DELIMITED-HOSTS> # Required. Example: cassandra.cassandra.svc.cluster.local
  12. - name: username
  13. value: <REPLACE-WITH-PASSWORD> # Optional. default: ""
  14. - name: password
  15. value: <REPLACE-WITH-PASSWORD> # Optional. default: ""
  16. - name: consistency
  17. value: <REPLACE-WITH-CONSISTENCY> # Optional. default: "All"
  18. - name: table
  19. value: <REPLACE-WITH-TABLE> # Optional. default: "items"
  20. - name: keyspace
  21. value: <REPLACE-WITH-KEYSPACE> # Optional. default: "dapr"
  22. - name: protoVersion
  23. value: <REPLACE-WITH-PROTO-VERSION> # Optional. default: "4"
  24. - name: replicationFactor
  25. value: <REPLACE-WITH-REPLICATION-FACTOR> # Optional. default: "1"

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.

Example

The following example uses the Kubernetes secret store to retrieve the username and password:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: state.cassandra
  8. version: v1
  9. metadata:
  10. - name: hosts
  11. value: <REPLACE-WITH-HOSTS>
  12. - name: username
  13. secretKeyRef:
  14. name: <KUBERNETES-SECRET-NAME>
  15. key: <KUBERNETES-SECRET-KEY>
  16. - name: password
  17. secretKeyRef:
  18. name: <KUBERNETES-SECRET-NAME>
  19. key: <KUBERNETES-SECRET-KEY>
  20. ...

Apply the configuration

In Kubernetes

To apply the Cassandra state store to Kubernetes, use the kubectl CLI:

  1. kubectl apply -f cassandra.yaml

Running locally

To run locally, create a components dir containing the YAML file and provide the path to the dapr run command with the flag --components-path.

Last modified February 16, 2021: Merge pull request #1235 from dapr/update-v0.11 (b4e9fbb)