はじめに
IBM CloudのManaged OpenShift環境で、Kafkaクラスタの検証を行うため、Red Hat AMQ StreamsをOperatorで入れた手順です。
環境概要

導入手順
OpenShiftクラスタの準備
事前準備として、IBM Cloud上にOpenShiftクラスタを作成します。
本検証では、OpenShift4.5(Gen2 VPC)のクラスタを1つ作成し、AMQ Streams用にWorker Node(Flavor:bx2.4×16)を3つのAZに合計3台用意しました。
参照:https://cloud.ibm.com/docs/openshift?topic=openshift-clusters
AMQ Streamsの導入
1. Projectの作成

2. AMQ Streams Operatorの導入



・Installed Operators画面でStatusがSucceededになることを確認します。


3. Kafkaクラスタの構成





4. Zookeeperクラスタの構成
Kafka構成のForm Viewの続きで、Zookeeperクラスタの構成を行います。







5. Topicの作成



6. メッセージのPublish/Subscribeのテスト
Kafka producerとKafka comsumerのコンテナをメッセージの出し入れを確認します。
・Kafkaクラスタと同一Project(namespace)にて実行します。
・Kafkaクラスタのbootstrapサービス名を確認します。
$ oc project
Using project "amqstreams" on server "https://xxxxx.containers.cloud.ibm.com:xxxxx".
$ oc get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-cluster-kafka-bootstrap ClusterIP 172.21.163.220 <none> 9091/TCP,9092/TCP,9093/TCP 12h
my-cluster-kafka-brokers ClusterIP None <none> 9091/TCP,9092/TCP,9093/TCP 12h
my-cluster-zookeeper-client ClusterIP 172.21.230.221 <none> 2181/TCP 12h
my-cluster-zookeeper-nodes ClusterIP None <none> 2181/TCP,2888/TCP,3888/TCP 12h
・Kafka producerをデプロイし、kafka-console-producer.shを実行し、プロンプトに任意のメッセージを入れます。
$ oc run kafka-producer -ti --image=registry.redhat.io/amq7/amq-streams-kafka-26-rhel7:1.6.0 --rm=true --restart=Never -- bin/kafka-console-producer.sh --broker-list my-cluster-kafka-bootstrap:9092 --topic my-topic
If you don't see a command prompt, try pressing enter.
>hello001
>hello002
>hello003
>hello004
>^Cpod "kafka-producer" deleted
pod amqstreams/kafka-producer terminated (Error)
・メッセージを確認するため、次にKafka consumerをデプロイし、kafka-console-consumer.shを実行します。
$ oc run kafka-consumer -ti --image=registry.redhat.io/amq7/amq-streams-kafka-26-rhel7:1.6.0 --rm=true --restart=Never -- bin/kafka-console-consumer.sh --bootstrap-server my-cluster-kafka-bootstrap:9092 --topic my-topic --from-beginning
If you don't see a command prompt, try pressing enter.
hello001
hello002
hello004
hello003
・メッセージが確認できました!
導入確認はここまでにして、次回はKafkaのメトリクス取得を行いたいと思います。
参考文献:
1.Using AMQ Streams on OpenShift
2.Chapter 4. Deploying AMQ Streams
3.Chapter 5. Setting up client access to the Kafka cluster
4.OpenShift + AMQ Streams(Apache Kafka) + QUARKUS で実現するアプリケーション