-
部署MT-Channel based Broker
URL:
https://knative.dev/docs/install/yaml-install/eventing/install-eventing-with-yaml/#optional-install-a-broker-layer
kubectl apply -f https://github.com/knative/eventing/releases/download/knative-v1.12.1/mt-channel-broker.yaml
-
MT-Channel based Broker 配置
-
是一种基于Channel的Broker的实现,它实际要使用的Channel取决于knative-eventing名称空间下的
ConfigMaps/config-br-default
的设定。 -
例如下面的示例配置中,Cluster级别要使用的默认chhannel遵循
configmaps/config-br-default-channel
中的定义,而event-demo名称空间下,则遵循ConfigMaps/kafka-channel
中的定义。apiVersion: v1 kind: ConfigMap metadata:name: config-br-defaultsnamespace: knative-eventing data:default-br-config: |clusterDefault:brokerClass: MTChannelBasedBrokerapiVersion: v1kind: ConfigMapname: config-br-default-channelnamespace: knative-eventingdelivery:retry: 10backoffPolicy: exponentialbackoffDelay: PT0.2SnamespaceDefaults:event-demo:brokerClass: MTChannelBasedBrokerapiVersion: v1kind: ConfigMapname: kafka-channelnamespace: knative-eventing
ConfigMaps/config-br-default-channe
l默认指定InMemoryChannel
为默认要使用的Channel类型,它的配置内容类似如下所示。apiVersion: v1 kind: ConfigMap metadata:name: config-br-default-channelnamespace: knative-eventing data:channel-template-spec: |apiVersion: messaging.knative.dev/v1kind: InMemoryChannel
若需要修改Broker在集群级别使用的Channel类型,只需要将上面配置中
data.channel-template-spec
键中kind的值加以修改即可。当然,我们也可以仅为特定的名称空间设定要使用的Channel类型。例如,遵循前面的配置,我们可在ConfigMaps/kafka-channel为event-demo
名称空间指定使用KafkaChannel,下面的配置给出了一个示例性的定义。apiVersion: v1 kind: ConfigMap metadata:name: kafka-channelnamespace: knative-eventing data:channel-template-spec: |apiVersion: messaging.knative.dev/v1beta1kind: KafkaChannelspec:numPartitions: 5replicationFactor: 1
-
-
验证
-
首先,在遵循全局设定的default名称空间创建Broker/broker01,并在创建成功后通过其status.annotations字段来确认其所使用的Channel类型。如下面的命令及其结果所示,Channel类型为
InMemoryChannel
,符合预期。~$ kubectl broker create broker01
~$ kubectl get broker broker01 -o jsonpath={.status.annotations} | jq . {"knative.dev/channelAPIVersion": "messaging.knative.dev/v1","knative.dev/channelAddress": "http://broker01-kne-trigger-kn-channel.default.svc.cluster.local","knative.dev/channelKind": "InMemoryChannel","knative.dev/channelName": "broker01-kne-trigger" }
-
而后,我们在为
MT-Channel based Broker
设定使用KafkaChannel的event-demo名称空间中创建Broker进行测试。如下面的命令及其结果所示,Channel类型为KafkaChannel
,符合预期。~$ kubectl broker create broker01 -n event-demo
~$ kubectl get broker broker01 -n event-demo -o jsonpath={.status.annotations} | jq . {"knative.dev/channelAPIVersion": "messaging.knative.dev/v1beta1","knative.dev/channelAddress": "http://broker01-kne-trigger-kn-channel.event-demo.svc.cluster.local","knative.dev/channelKind": "KafkaChannel","knative.dev/channelName": "broker01-kne-trigger" }
-
-
MT-Channel based Broker的功能与特性与其底层所使用的Channel关联性不大,具体broker/trigger案例参照上面。但需要注意的是,KafkaChannel的功能及我取决于其底层的Kafka,因而其更适合于生产环境使用。