Cloudstate

关于Cloudstate状态存储组件的详细信息

配置

要设置Cloudstate状态存储,请创建一个类型为state.cloudstate的组件。 请参阅本指南,了解如何创建和应用状态存储配置。

  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>

元数据字段规范

字段必填详情Example
hostsY指定Cloudstate API 地址“localhost:8013”
serverPortY指定要在 Dapr 中打开的 Cloudstate 回调端口。 这需要是你的应用程序或 Dapr 没有占用的端口“8080”

由于 Cloudstate 在 pod 中作为额外的sidecar运行,你可以通过 localhost 以默认端口 8013 访问它。

介绍

Cloudstate-Dapr 的独特之处在于,它使开发人员能够通过让 Cloudstate 作为 紧邻 Dapr 的sidecar运行来实现高吞吐量、低延迟的场景,以此将状态保持在计算单元附近以获得最佳性能,同时提供可安全扩缩容的多个实例之间的复制能力。 这是由于Cloudstate在其边车之间形成了一个 Akka 集群,并在内存中复制实体。

Dapr 利用 Cloudstate 的 CRDT (无冲突可复制数据类型) 功能与last-write-wins的语义。

安装 Cloudstate

要在 Kubernetes 集群上安装 Cloudstate,请执行以下命令:

  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

这会把 Cloudstate 安装到版本为 0.5.0cloudstate 命名空间中。

应用配置

在Kubernetes中

要将Cloudstate状态存储应用到Kubernetes,请使用kubectl CLI。

  1. kubectl apply -f cloudstate.yaml

注入 Cloudstate sidecar到 Dapr

下面的例子展示了如何将 Cloudstate 边车手动注入到启用了Dapr的deployment中。

请注意,cloudstate-sidecar容器的HTTP_PORThost中Cloudstate组件yaml中要使用的端口。

  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

相关链接