Creating a Broker

Once you have installed Knative Eventing and a Broker implementation, you can create an instance of a Broker.

Note

Knative Eventing provides by default the MTChannelBasedBroker. Its default backing channel is the InMemoryChannel. InMemoryChannel should not be used in production. Other Broker types and their configuration options can be found under Available Broker types.

You can create a Broker by using the kn CLI or by applying YAML files using kubectl.

knkubectl

  1. You can create a Broker by entering the following command:

    1. kn broker create <broker-name> -n <namespace>

    This will create a new Broker of your default Broker class and default Broker configuration (both defined in the config-br-defaults ConfigMap).

    Note

    If you choose not to specify a namespace, the Broker will be created in the current namespace.

    Note

    If you have multiple Broker classes installed in your cluster, you can specify the Broker class via the --class parameter, e.g.:

    1. kn broker create <broker-name> -n <namespace> --class MTChannelBasedBroker
  2. Optional: Verify that the Broker was created by listing existing Brokers:

    1. kn broker list
  3. Optional: You can also verify the Broker exists by describing the Broker you have created:

    1. kn broker describe <broker-name>

The YAML in the following example creates a Broker named default.

  1. Create a Broker by creating a YAML file using the following template:

    1. apiVersion: eventing.knative.dev/v1
    2. kind: Broker
    3. metadata:
    4. name: <broker-name>
    5. namespace: <namespace>

    This creates a new Broker using the default Broker class and default Broker configuration, both of which are defined in the config-br-defaults ConfigMap.

  2. Apply the YAML file:

    1. kubectl apply -f <filename>.yaml

    Where <filename> is the name of the file you created in the previous step.

  3. Optional: Verify that the Broker is working correctly:

    1. kubectl -n <namespace> get broker <broker-name>

    This shows information about your Broker. If the Broker is working correctly, it shows a READY status of True:

    1. NAME READY REASON URL AGE
    2. default True http://broker-ingress.knative-eventing.svc.cluster.local/default/default 1m

    If the READY status is False, wait a few moments and then run the command again.

Broker class options

When a Broker is created without a specified eventing.knative.dev/broker.class annotation, the default MTChannelBasedBroker Broker class is used, as specified by default in the config-br-defaults ConfigMap.

In case you have multiple Broker classes installed in your cluster and want to use a non-default Broker class for a Broker, you can modify the eventing.knative.dev/broker.class annotation and spec.config for the Broker object.

  1. Set the eventing.knative.dev/broker.class annotation. Replace MTChannelBasedBroker in the following example with the class type you want to use. Be aware that the Broker class annoation is immutable and thus can’t be updated after the Broker got created:

    1. apiVersion: eventing.knative.dev/v1
    2. kind: Broker
    3. metadata:
    4. annotations:
    5. eventing.knative.dev/broker.class: MTChannelBasedBroker
    6. name: default
    7. namespace: default
  2. Configure the spec.config with the details of the ConfigMap that defines the required configuration for the Broker class (e.g. with some Channel configurations in case of the MTChannelBasedBroker):

    1. apiVersion: eventing.knative.dev/v1
    2. kind: Broker
    3. metadata:
    4. annotations:
    5. eventing.knative.dev/broker.class: MTChannelBasedBroker
    6. name: default
    7. namespace: default
    8. spec:
    9. config:
    10. apiVersion: v1
    11. kind: ConfigMap
    12. name: config-br-default-channel
    13. namespace: knative-eventing

For further information about configuring a default Broker class cluster wide or on a per namespace basis, check the Administrator configuration options.