HashiCorp Consul

Detailed information on the HashiCorp Consul state store component

配置

To setup Hashicorp Consul state store create a component of type state.consul. 请参阅本指南,了解如何创建和应用状态存储配置。

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: state.consul
  8. version: v1
  9. metadata:
  10. - name: datacenter
  11. value: <REPLACE-WITH-DATA-CENTER> # Required. Example: dc1
  12. - name: httpAddr
  13. value: <REPLACE-WITH-CONSUL-HTTP-ADDRESS> # Required. Example: "consul.default.svc.cluster.local:8500"
  14. - name: aclToken
  15. value: <REPLACE-WITH-ACL-TOKEN> # Optional. default: ""
  16. - name: scheme
  17. value: <REPLACE-WITH-SCHEME> # Optional. default: "http"
  18. - name: keyPrefixPath
  19. value: <REPLACE-WITH-TABLE> # Optional. default: "" Example: dc1
  20. - name: httpAddr
  21. value: <REPLACE-WITH-CONSUL-HTTP-ADDRESS> # Required. Example: "consul.default.svc.cluster.local:8500"
  22. - name: aclToken
  23. value: <REPLACE-WITH-ACL-TOKEN> # Optional. default: ""
  24. - name: scheme
  25. value: <REPLACE-WITH-SCHEME> # Optional. default: "http"
  26. - name: keyPrefixPath
  27. value: <REPLACE-WITH-TABLE> # Optional. default: "" Example: dc1
  28. - name: httpAddr
  29. value: <REPLACE-WITH-CONSUL-HTTP-ADDRESS> # Required. Example: "consul.default.svc.cluster.local:8500"
  30. - name: aclToken
  31. value: <REPLACE-WITH-ACL-TOKEN> # Optional. default: ""
  32. - name: scheme
  33. value: <REPLACE-WITH-SCHEME> # Optional. default: "http"
  34. - name: keyPrefixPath
  35. value: <REPLACE-WITH-TABLE> # Optional. default: ""

Warning

以上示例将 Secret 明文存储。 更推荐的方式是使用 Secret 组件, 这里

元数据字段规范

字段必填详情示例
datacenterYDatacenter to use“dc1”
httpAddrYAddress of the Consul server“consul.default.svc.cluster.local:8500”
aclTokenNPer Request ACL Token. Default is “”“token”
schemeNScheme is the URI scheme for the Consul server. Default is “http”“http”
keyPrefixPathNKey prefix path in Consul. Default is “”“dapr”

Setup HashiCorp Consul

You can run Consul locally using Docker:

  1. docker run -d --name=dev-consul -e CONSUL_BIND_INTERFACE=eth0 consul

然后您可以使用 localhost:8500 与服务器交互。

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

  1. helm install consul stable/consul

This installs Consul into the default namespace. To interact with Consul, find the service with: kubectl get svc consul.

For example, if installing using the example above, the Consul host address would be:

consul.default.svc.cluster.local:8500

相关链接