Dapr 配置选项概述

    自托管模式的 Sidecar

    在自托管模式下,Dapr 配置通过配置文件进行定义,如 。 默认情况下,Dapr sidecar 会在默认的 Dapr 目录下寻找运行时配置,在 Linux / MacOS操作系统下,位置为 $HOME/.dapr/config.yaml , Windows操作系统下则为 %USERPROFILE%\.dapr\config.yaml

    也可以在运行 dapr run CLI 命令时,通过使用 --config 标志来制定 Dapr sidecar 所读取的配置文件所在的位置。

    Kubernetes 模式的 Sidecar

    在 Kubernetes 模式下,Dapr 可以通过集群中的一个配置 CRD 进行配置。 例如:

    您也可以使用 Dapr CLI 工具列举查看当前的配置 CRD 列表:

    1. dapr configurations -k

    也可以使用 dapr.io/config 注解对指定的 Dapr sidecar 应用特定的配置。 例如:

    Note: There are more Kubernetes annotations available to configure the Dapr sidecar on activation by sidecar Injector system service.

    Dapr 应用 sidecar 提供以下配置选项;

    追踪

    链路追踪配置用于为应用程序开启调用链追踪功能。

    1. tracing:
    2. samplingRate: "1"
    3. zipkin:
    4. endpointAddress: "http://zipkin.default.svc.cluster.local:9411/api/v2/spans"

    下面的表格给出了调用链追踪功能可配置的属性

    samplingRate 用来控制调用链追踪是否启用。 要禁用采样率 , 可以在配置文件中设置 samplingRate : "0" 。 SamplingRate 的有效值在0到1之间。 系统将根据采样率配置的数值决定一条 trace span 是否要被采样。 如果设置 samplingRate : "1" ,将会对所有的调用链进行采样。 默认情况下,采样率配置为 (0.0001),即每10,000条请求中会有一条被采样。

    See Observability distributed tracing for more information

    度量

    配置中的 metrics 部分用来为应用开启或禁用度量功能。

    Configuration sepc下的 metrics 部分包含以下属性:

    下面的表格给出了度量功能可配置的属性

    See metrics documentation for more information

    中间件

    中间件配置用于配置一系列可命名的HTTP管道处理器。Configuration spec 下的httpPipeline 部分包含以下的配置属性:

    1. handlers:
    2. - name: oauth2
    3. - name: uppercase
    4. type: middleware.http.uppercase

    See Middleware pipelines for more information

    限定作用域的密钥储存控制

    See the Scoping secrets guide for information and examples on how to scope secrets to an application.

    Access Control allow lists for building block APIs

    See the selectively enable Dapr APIs on the Dapr sidecar guide for information and examples on how to set ACLs on the building block APIs lists.

    Access Control allow lists for service invocation API

    See the Allow lists for service invocation guide for information and examples on how to set allow lists with ACLs which using service invocation API.

    Turning on preview features

    See the preview features guide for information and examples on how to opt-in to preview features for a release. Preview feature enable new capabilities to be added that still need more time until they become generally available (GA) in the runtime.

    下面的yaml内容展示了一个可以被应用于Dapr sidecar的配置文件:

    控制平面配置

    在 Dapr 控制平面系统中,安装了一个名为default 的配置文件,用于应用全局配置。 这个配置仅在Dapr部署到Kubernetes中时生效。

    在 Dapr 控制平面中,可以使用以下配置项:

    1. apiVersion: dapr.io/v1alpha1
    2. kind: Configuration
    3. metadata:
    4. name: default
    5. namespace: default
    6. spec:
    7. mtls:
    8. enabled: true