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

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: [COMPONENT-NAME]
  namespace: [COMPONENT-NAMESPACE]
spec:
  type: [COMPONENT-TYPE]
  version: v1
  initTimeout: [TIMEOUT-DURATION]
  ignoreErrors: [BOOLEAN]
  metadata:
  - name: [METADATA-NAME]
    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.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: messagebus
spec:
  type: pubsub.mqtt
  version: v1
  metadata:
    - name: consumerID
      value: "{uuid}"
    - name: url
      value: "tcp://admin:public@localhost:1883"
    - name: qos
      value: 1
    - name: retain
      value: "false"
    - name: cleanSession
      value: "false"

Further reading