Component schema

The basic schema for a Dapr component

Dapr defines and registers components using a CustomResourceDefinition. All components are defined as a CRD and can be applied to any hosting environment where Dapr is running, not just Kubernetes.

Format

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: [COMPONENT-NAME]
  5. namespace: [COMPONENT-NAMESPACE]
  6. spec:
  7. type: [COMPONENT-TYPE]
  8. version: v1
  9. initTimeout: [TIMEOUT-DURATION]
  10. ignoreErrors: [BOOLEAN]
  11. metadata:
  12. - name: [METADATA-NAME]
  13. value: [METADATA-VALUE]

Fields

FieldRequiredDetailsExample
apiVersionYThe version of the Dapr (and Kubernetes if applicable) API you are callingdapr.io/v1alpha1
kindYThe type of CRD. For components is must always be ComponentComponent
metadata-Information about the component registration
metadata.nameYThe name of the componentprod-statestore
metadata.namespaceNThe namespace for the component for hosting environments with namespacesmyapp-namespace
spec-Detailed information on the component resource
spec.typeYThe type of the componentstate.redis
spec.versionYThe version of the componentv1
spec.initTimeoutNThe timeout duration for the initialization of the component. Default is 30s5m, 1h, 20s
spec.ignoreErrorsNTells the Dapr sidecar to continue initialization if the component fails to load. Default is falsefalse
spec.metadata-A key/value pair of component specific configuration. See your component definition for fields

Special metadata values

Metadata values can contain a {uuid} tag that is replaced with a randomly generate UUID when the Dapr sidecar starts up. A new UUID is generated on every start up. It can be used, for example, to have a pod on Kubernetes with multiple application instances consuming a shared MQTT subscription. Below is an example of using the {uuid} tag.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: messagebus
  5. spec:
  6. type: pubsub.mqtt
  7. version: v1
  8. metadata:
  9. - name: consumerID
  10. value: "{uuid}"
  11. - name: url
  12. value: "tcp://admin:public@localhost:1883"
  13. - name: qos
  14. value: 1
  15. - name: retain
  16. value: "false"
  17. - name: cleanSession
  18. value: "false"

Further reading

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