Cloudstate

Detailed information on the Cloudstate state store component

Component format

To setup Cloudstate state store create a component of type state.cloudstate. See this guide on how to create and apply a state store configuration.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: state.cloudstate
  8. version: v1
  9. metadata:
  10. - name: host
  11. value: <REPLACE-WITH-HOST>
  12. - name: serverPort
  13. value: <REPLACE-WITH-PORT>

Spec metadata fields

FieldRequiredDetailsExample
hostsYSpecifies the address for the Cloudstate API“localhost:8013”
serverPortYSpecifies the port to be opened in Dapr for Cloudstate to callback to. This can be any free port that is not used by either your application or Dapr“8080”

Since Cloudstate is running as an additional sidecar in the pod, you can reach it via localhost with the default port of 8013.

Introduction

The Cloudstate-Dapr integration is unique in the sense that it enables developers to achieve high-throughput, low latency scenarios by leveraging Cloudstate running as a sidecar next to Dapr, keeping the state near the compute unit for optimal performance while providing replication between multiple instances that can be safely scaled up and down. This is due to Cloudstate forming an Akka cluster between its sidecars with replicated in-memory entities.

Dapr leverages Cloudstate’s CRDT capabilities with last-write-wins semantics.

Setup Cloudstate

To install Cloudstate on your Kubernetes cluster, run the following commands:

  1. kubectl create namespace cloudstate
  2. kubectl apply -n cloudstate -f https://github.com/cloudstateio/cloudstate/releases/download/v0.5.0/cloudstate-0.5.0.yaml

This installs Cloudstate into the cloudstate namespace with version 0.5.0.

Apply the configuration

In Kubernetes

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

  1. kubectl apply -f cloudstate.yaml

Running the Cloudstate sidecar alongside Dapr

The next examples shows you how to manually inject a Cloudstate sidecar into a Dapr enabled deployment:

Notice the HTTP_PORT for the cloudstate-sidecar container is the port to be used in the Cloudstate component yaml in host.

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. annotations:
  5. name: test-dapr-app
  6. namespace: default
  7. labels:
  8. app: test-dapr-app
  9. spec:
  10. replicas: 1
  11. selector:
  12. matchLabels:
  13. app: test-dapr-app
  14. template:
  15. metadata:
  16. annotations:
  17. dapr.io/enabled: "true"
  18. dapr.io/app-id: "testapp"
  19. labels:
  20. app: test-dapr-app
  21. spec:
  22. containers:
  23. - name: user-container
  24. image: nginx
  25. - name: cloudstate-sidecar
  26. env:
  27. - name: HTTP_PORT
  28. value: "8013"
  29. - name: USER_FUNCTION_PORT
  30. value: "8080"
  31. - name: REMOTING_PORT
  32. value: "2552"
  33. - name: MANAGEMENT_PORT
  34. value: "8558"
  35. - name: SELECTOR_LABEL_VALUE
  36. value: test-dapr-app
  37. - name: SELECTOR_LABEL
  38. value: app
  39. - name: REQUIRED_CONTACT_POINT_NR
  40. value: "1"
  41. - name: JAVA_OPTS
  42. value: -Xms256m -Xmx256m
  43. image: cloudstateio/cloudstate-proxy-no-store:0.5.0
  44. livenessProbe:
  45. httpGet:
  46. path: /alive
  47. port: 8558
  48. scheme: HTTP
  49. initialDelaySeconds: 2
  50. failureThreshold: 20
  51. periodSeconds: 2
  52. readinessProbe:
  53. httpGet:
  54. path: /ready
  55. port: 8558
  56. scheme: HTTP
  57. initialDelaySeconds: 2
  58. failureThreshold: 20
  59. periodSeconds: 10
  60. resources:
  61. limits:
  62. memory: 512Mi
  63. requests:
  64. cpu: 400m
  65. memory: 512Mi
  66. ---
  67. apiVersion: rbac.authorization.k8s.io/v1
  68. kind: Role
  69. metadata:
  70. name: cloudstate-pod-reader
  71. namespace: default
  72. rules:
  73. - apiGroups:
  74. - ""
  75. resources:
  76. - pods
  77. verbs:
  78. - get
  79. - watch
  80. - list
  81. ---
  82. apiVersion: rbac.authorization.k8s.io/v1
  83. kind: RoleBinding
  84. metadata:
  85. name: cloudstate-read-pods-default
  86. namespace: default
  87. roleRef:
  88. apiGroup: rbac.authorization.k8s.io
  89. kind: Role
  90. name: cloudstate-pod-reader
  91. subjects:
  92. - kind: ServiceAccount
  93. name: default

Related links

Last modified March 18, 2021: Merge pull request #1321 from dapr/aacrawfi/logos (9a399d5)