Apache Kafka Channel Example

    Creating a KafkaChannel channel CRD

    Create a new object by configuring the YAML file as follows:

    To configure the usage of the KafkaChannel CRD as the , edit the default-ch-webhook ConfigMap as follows:

    1. cat <<-EOF | kubectl apply -f -
    2. ---
    3. apiVersion: v1
    4. kind: ConfigMap
    5. metadata:
    6. name: default-ch-webhook
    7. namespace: knative-eventing
    8. # Configuration for defaulting channels that do not specify CRD implementations.
    9. default-ch-config: |
    10. clusterDefault:
    11. apiVersion: messaging.knative.dev/v1beta1
    12. kind: KafkaChannel
    13. spec:
    14. replicationFactor: 1
    15. EOF

    Creating an Apache Kafka channel using the default channel configuration

    Now that KafkaChannel is set as the default channel configuration, you can use the channels.messaging.knative.dev CRD to create a new Apache Kafka channel, using the generic Channel:

    1. cat <<-EOF | kubectl apply -f -
    2. ---
    3. apiVersion: messaging.knative.dev/v1
    4. kind: Channel
    5. metadata:
    6. name: testchannel-one
    7. EOF

    Check Kafka for a testchannel topic. With Strimzi this can be done by using the command:

    1. kubectl -n kafka exec -it my-cluster-kafka-0 -- bin/kafka-topics.sh --zookeeper localhost:2181 --list

    The Apache Kafka topic that is created by the channel implementation is prefixed with knative-messaging-kafka. This indicates it is an Apache Kafka channel from Knative. It contains the name of the namespace, default in this example, followed by the actual name of the channel.

    To setup a broker that will use the new default Kafka channels, you must create a new default broker, using the command:

    1. apiVersion: eventing.knative.dev/v1
    2. metadata:
    3. name: default
    4. EOF

    This will give you two pods, such as:

    1. default-broker-filter-64658fc79f-nf596 1/1 Running 0 15m
    2. default-broker-ingress-ff79755b6-vj9jt 1/1 Running 0 15m

    Inside the Apache Kafka cluster you should see two new topics, such as:

    1. ...
    2. knative-messaging-kafka.default.default-kn2-ingress
    3. knative-messaging-kafka.default.default-kn2-trigger
    4. ...

    Creating a service and trigger to use the Apache Kafka broker

    1. Install ksvc, using the command:

    2. Install a source that publishes to the default broker

      1. kubectl apply -f 020-k8s-events.yaml
    3. Create a trigger that routes the events to the ksvc:

      1. kubectl apply -f 030-trigger.yaml

    Now that your Eventing cluster is configured for Apache Kafka, you can verify your configuration with the following options.

    1. kubectl logs --selector='serving.knative.dev/service=broker-kafka-display' -c user-container