# Setup Cassandra ## Locally You can run Cassandra locally with the Datastax Docker image: ``` 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`. ## Kubernetes The easiest way to install Cassandra on Kubernetes is by using the [Helm chart](https://github.com/helm/charts/tree/master/incubator/cassandra): ``` kubectl create namespace cassandra 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`: ```yaml apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: namespace: spec: type: state.cassandra metadata: - name: hosts value: # Required. Example: cassandra.cassandra.svc.cluster.local - name: username value: # Optional. default: "" - name: password value: # Optional. default: "" - name: consistency value: # Optional. default: "All" - name: table value: # Optional. default: "items" - name: keyspace value: # Optional. default: "dapr" - name: protoVersion value: # Optional. default: "4" - name: replicationFactor value: # Optional. default: "1" ``` The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described [here](../../concepts/secrets/README.md) The following example uses the Kubernetes secret store to retrieve the username and password: ```yaml apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: namespace: spec: type: state.cassandra metadata: - name: hosts value: - name: username secretKeyRef: name: key: - name: password secretKeyRef: name: key: ... ``` ## Apply the configuration ### In Kubernetes To apply the Cassandra state store to Kubernetes, use the `kubectl` CLI: ``` kubectl apply -f cassandra.yaml ``` ### Running locally The Dapr CLI will automatically create a directory named `components` in your current working directory with a Redis component. To use Cassandra, replace the redis.yaml file with the cassandra.yaml above.