其他分享
首页 > 其他分享> > kafka-broker

kafka-broker

作者:互联网

/root/knative-in-practise/eventing/kafka/05-kafka-broker

 部署kafka-broker-01

[root@master 05-kafka-broker]# cat 01-eventing-kafka-controller.yaml |grep gcr
          image: gcr.io/knative-releases/knative.dev/eventing-kafka-broker/control-plane/cmd/kafka-controller@sha256:7dd249f85b8f21cf4d5ec5a3273462c885b07130183441ad7950721bf7e76be3
          image: gcr.io/knative-releases/knative.dev/eventing-kafka-broker/control-plane/cmd/webhook-kafka@sha256:eee89fc7becb46c450ec5bdff4a975b9f5f2613b225debdbec17451b72f056e8
[root@master 05-kafka-broker]# cat 01-eventing-kafka-controller.yaml |grep chuan
          image: gexuchuan123/eventing-kafka-broker-control-plane-cmd-kafka-controller:v1
          image: gexuchuan123/eventing-kafka-broker-control-plane-cmd-webhook-kafka:v1
[root@master 05-kafka-broker]# kubectl get po -nknative-eventing 
NAME                                        READY   STATUS             RESTARTS        AGE
kafka-controller-7c44568b45-xdfkh           1/1     Running            2 (2m57s ago)   17m
kafka-webhook-eventing-7ff8b8896d-8lqfc     1/1     Running            0               17m

 部署kafka-broker-02

[root@master 05-kafka-broker]# cat 02-eventing-kafka-broker.yaml |grep gcr
          image: gcr.io/knative-releases/knative-kafka-broker-dispatcher:e0d71c0bde279dc258d4e833c99a96899a358f37f85415dbf04a78965bd38842
          image: gcr.io/knative-releases/knative-kafka-broker-receiver:520dc2f082aa8a1e2134e485f5c636ab8400e82d5a701a11803d42f11b0abbf3
[root@master 05-kafka-broker]# cat 02-eventing-kafka-broker.yaml |grep chuan
          image: gexuchuan123/knative-kafka-broker-dispatcher:v1
          image: gexuchuan123/knative-kafka-broker-receiver:v1
[root@master 05-kafka-broker]# kubectl get po -nknative-eventing  #验证kafka-broker
NAME                                        READY   STATUS    RESTARTS         AGE
kafka-broker-dispatcher-556df6777c-55tmv    1/1     Running   0                2m18s  #实现消息的分发
kafka-broker-receiver-7b69b8648b-tkcrd      1/1     Running   0                2m18s  #实现消息的接收

 修改默认配置 kafka-channel 和 kafka-broker都设置在event-demo名称空间

[root@master 05-kafka-broker]# kubectl get cm config-br-defaults -oyaml -nknative-eventing
apiVersion: v1
data:
  default-br-config: |
    clusterDefault:
      brokerClass: MTChannelBasedBroker
      apiVersion: v1
      kind: ConfigMap
      name: config-br-default-channel
      namespace: knative-eventing
      delivery:
        retry: 10
        backoffPolicy: exponential
        backoffDelay: PT0.2S
    namespaceDefaults:
      event-demo:
        brokerClass: Kafka
        apiVersion: v1
        kind: ConfigMap
        name: kafka-broker-config
        namespace: knative-eventing

 

[root@master 05-kafka-broker]# kubectl get cm -nknative-eventing  #查看默认参数
NAME                                   DATA   AGE
config-br-default-channel              1      2d14h
config-br-defaults                     1      2d14h
config-features                        6      2d14h
config-kafka                           2      2d14h
config-kafka-broker-data-plane         4      5m36s
config-kafka-source-defaults           1      2d16h
config-kreference-mapping              1      2d14h
config-leader-election                 1      2d14h
config-leader-election-kafkachannel    4      2d14h
config-logging                         3      2d14h
config-observability                   1      2d14h
config-ping-defaults                   1      2d14h
config-tracing                         1      2d14h
default-ch-webhook                     1      2d14h
istio-ca-root-cert                     1      2d16h
kafka-broker-brokers-triggers          1      27m
kafka-broker-config                    3      29m
kafka-channel-channels-subscriptions   1      27m
kafka-channel-config                   1      29m
kafka-config-logging                   1      29m
kafka-sink-sinks                       1      27m
kafka-source-sources                   1      27m
kube-root-ca.crt                       1      2d16h
[root@master 05-kafka-broker]# kubectl get  cm  kafka-broker-config  -oyaml -nknative-eventing
apiVersion: v1
data:
  bootstrap.servers: my-cluster-kafka-bootstrap.kafka:9092
  default.topic.partitions: "10"
  default.topic.replication.factor: "3" #默认参数
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"bootstrap.servers":"my-cluster-kafka-bootstrap.kafka:9092","default.topic.partitions":"10","default.topic.replication.factor":"3"},"kind":"ConfigMap","metadata":{"annotations":{},"labels":{"kafka.eventing.knative.dev/release":"devel"},"name":"kafka-broker-config","namespace":"knative-eventing"}}
  labels:
    kafka.eventing.knative.dev/release: devel
  name: kafka-broker-config
  namespace: knative-eventing
  resourceVersion: "148435"
  uid: 6439bbeb-f7d2-4342-9a18-19cae25cb808
修改1  kafka-broker-03
[root@master 05-kafka-broker]# cat 03-configmap-kafka-broker-config.yaml #修改kafkabroker副本数为1,对应kafka 数量 apiVersion: v1 kind: ConfigMap metadata: name: kafka-broker-config namespace: knative-eventing data: # Number of topic partitions default.topic.partitions: "10" # Replication factor of topic messages. default.topic.replication.factor: "1" # A comma separated list of bootstrap servers. (It can be in or out the k8s cluster) bootstrap.servers: "my-cluster-kafka-bootstrap.kafka:9092"
[root@master 05-kafka-broker]# cat 04-default-channel-config.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: default-ch-webhook
  namespace: knative-eventing
data:
  default-ch-config: |
    clusterDefault:
      apiVersion: messaging.knative.dev/v1
      kind: InMemoryChannel  #可将全空间替换为KafkaChannel
    namespaceDefaults: #设置default和event-demo两个名称空间为KafkaChannel
      default:
        apiVersion: messaging.knative.dev/v1beta1
        kind: KafkaChannel
        spec:
          numPartitions: 5
          replicationFactor: 1
      event-demo:
        apiVersion: messaging.knative.dev/v1beta1
        kind: KafkaChannel
        spec:
          numPartitions: 5
          replicationFactor: 1

 

[root@master 05-kafka-broker]# cat 05-configmap-default-br-config.yaml  #设置event-demo空间下创建kafka-broker
apiVersion: v1
kind: ConfigMap
metadata:
  name: config-br-defaults
  namespace: knative-eventing
data:
  default-br-config: |
    clusterDefault:
      brokerClass: MTChannelBasedBroker
      apiVersion: v1
      kind: ConfigMap
      name: config-br-default-channel
      namespace: knative-eventing
      delivery:
        retry: 10
        backoffPolicy: exponential
        backoffDelay: PT0.2S
    namespaceDefaults:
      event-demo:
        brokerClass: Kafka
        apiVersion: v1
        kind: ConfigMap
        name: kafka-broker-config
        namespace: knative-eventing
[root@master 05-kafka-broker]# kn broker create broker01 -nevent-demo  
[root@master 05-kafka-broker]# kn broker list -nevent-demo  #验证broker
NAME       URL                                                                                  AGE    CONDITIONS   READY   REASON
broker01   http://kafka-broker-ingress.knative-eventing.svc.cluster.local/event-demo/broker01   2s     7 OK / 7     True    
broker02   http://kafka-broker-ingress.knative-eventing.svc.cluster.local/event-demo/broker02   119s   7 OK / 7     True

 

kubectl  edit cm config-br-default-channel  -nknative-eventing
KafkaChannel

[root@master ~]# kubectl run client1 --image=ikubernetes/admin-box:v1.2 --restart=Never --rm -it --command -- bin/bash

[root@master 05-kafka-broker]# kn trigger create mytr01 --broker broker01 --sink ksvc:event-display:default -nevent-demo

event-display      在default名称空间

trigger  broker    在event-demo名称空间

[root@master 05-kafka-broker]# kn trigger list -A
NAMESPACE    NAME     BROKER     SINK                 AGE     CONDITIONS   READY   REASON
event-demo   mytr01   broker01   ksvc:event-display   3m43s   6 OK / 6     True
curl -v "http://kafka-broker-ingress.knative-eventing.svc.cluster.local/event-demo/broker01" \
-X POST \
-H "Ce-Id: 0001" \
-H "Ce-Specversion: 1.0" \
-H "Ce-Type: com.magedu.file.image" \
-H "Ce-Source: Curl" \
-H "Content-Type: application/json" \
-d '{"msg":"An Event to KafkaBroker"}'
[root@master ~]# kubectl logs -f event-display-00001-deployment-6f64bdfbbf-vkv6l -cuser-container
☁️  cloudevents.Event
Context Attributes,
  specversion: 1.0
  type: com.magedu.file.image
  source: Curl
  id: 0001
  datacontenttype: application/json
Data,
  {
    "msg": "An Event to KafkaBroker"

 

标签:eventing,broker,kafka,default,knative,config
来源: https://www.cnblogs.com/gxc888/p/16026304.html