Setup auf KRAFT mit start über den Service `setup` umgestellt
authorKai Moritz <kai@juplo.de>
Tue, 1 Nov 2022 15:39:57 +0000 (16:39 +0100)
committerKai Moritz <kai@juplo.de>
Sat, 12 Nov 2022 09:16:48 +0000 (10:16 +0100)
* Das Compose-Setup auf KRAFT mit bitnami-Images umgestellt.
* Der Zookeeper wird dann durch eine Controller-Instanz ersetzt
* Durch die definierten Abhängigkeiten kann die gesamte Infrastruktur
  bequme mit `docker-compose up setup` im Hintergrund hochgefahren werden.
  Der Service läuft zwar im Vordergrund, aber die benötigten Services
  werden automatisch im Hintergrund gestartet und der Setup-Service
  beendet sich ja ohnehin nach dem Erzeugen der Topics.

README.sh
docker-compose.yml

index 0daad74..30d4be2 100755 (executable)
--- a/README.sh
+++ b/README.sh
@@ -9,7 +9,7 @@ then
   exit
 fi
 
-docker-compose up -d zookeeper kafka-1 kafka-2 kafka-3 cli
+docker-compose up -d kafka-1 kafka-2 kafka-3 cli
 docker-compose rm -svf producer
 
 if [[
@@ -23,10 +23,8 @@ else
   docker image ls $IMAGE
 fi
 
-echo "Waiting for the Kafka-Cluster to become ready..."
-docker-compose exec cli cub kafka-ready -b kafka:9092 1 60 > /dev/null 2>&1 || exit 1
 docker-compose up setup
-docker-compose up -d
+docker-compose up -d producer
 sleep 5
 
 docker-compose exec cli kafkacat -b kafka:9092 -t test -q -c 20 -f'topic=%t\tpartition=%p\toffset=%o\tkey=%k\tvalue=%s\n'
index d9f15c8..19a1f19 100644 (file)
@@ -1,39 +1,58 @@
 version: '3.2'
 services:
-  zookeeper:
-    image: confluentinc/cp-zookeeper:7.1.3
+  kafka-0:
+    image: bitnami/kafka:3.3.1
     environment:
-      ZOOKEEPER_CLIENT_PORT: 2181
-    ports:
-      - 2181:2181
+      KAFKA_ENABLE_KRAFT: 'yes'
+      KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw
+      KAFKA_CFG_PROCESS_ROLES: controller
+      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
+      KAFKA_CFG_LISTENERS: CONTROLLER://:9092
+      KAFKA_CFG_ADVERTISED_LISTENERS: " "
+      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT
+      KAFKA_BROKER_ID: 0
+      KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka-0:9092
+      ALLOW_PLAINTEXT_LISTENER: 'yes'
+      KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
+      KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
 
   kafka-1:
-    image: confluentinc/cp-kafka:7.1.3
+    image: bitnami/kafka:3.3.1
     environment:
+      KAFKA_ENABLE_KRAFT: 'yes'
+      KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw
+      KAFKA_CFG_PROCESS_ROLES: broker
+      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
+      KAFKA_CFG_LISTENERS: BROKER://:9092, LOCALHOST://:9081
+      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT
+      KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-1:9092, LOCALHOST://localhost:9081
       KAFKA_BROKER_ID: 1
-      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
-      KAFKA_LISTENERS: DOCKER://:9092, LOCALHOST://:9081
-      KAFKA_ADVERTISED_LISTENERS: DOCKER://kafka-1:9092, LOCALHOST://localhost:9081
-      KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER
-      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER:PLAINTEXT, LOCALHOST:PLAINTEXT
-      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
-      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
+      KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka-0:9092
+      ALLOW_PLAINTEXT_LISTENER: 'yes'
+      KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER
+      KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
+      KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
     ports:
       - 9081:9081
     depends_on:
-      - zookeeper
+      - kafka-0
 
   kafka-2:
-    image: confluentinc/cp-kafka:7.1.3
+    image: bitnami/kafka:3.3.1
     environment:
+      KAFKA_ENABLE_KRAFT: 'yes'
+      KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw
+      KAFKA_CFG_PROCESS_ROLES: broker
+      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
+      KAFKA_CFG_LISTENERS: BROKER://:9092, LOCALHOST://:9082
+      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT
+      KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-2:9092, LOCALHOST://localhost:9082
       KAFKA_BROKER_ID: 2
-      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
-      KAFKA_LISTENERS: DOCKER://:9092, LOCALHOST://:9082
-      KAFKA_ADVERTISED_LISTENERS: DOCKER://kafka-2:9092, LOCALHOST://localhost:9082
-      KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER
-      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER:PLAINTEXT, LOCALHOST:PLAINTEXT
-      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
-      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
+      KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka-0:9092
+      ALLOW_PLAINTEXT_LISTENER: 'yes'
+      KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER
+      KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
+      KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
     ports:
       - 9092:9082
       - 9082:9082
@@ -42,23 +61,28 @@ services:
         aliases:
           - kafka
     depends_on:
-      - zookeeper
+      - kafka-0
 
   kafka-3:
-    image: confluentinc/cp-kafka:7.1.3
+    image: bitnami/kafka:3.3.1
     environment:
+      KAFKA_ENABLE_KRAFT: 'yes'
+      KAFKA_KRAFT_CLUSTER_ID: r7dMBY60T16TrNCGeXniLw
+      KAFKA_CFG_PROCESS_ROLES: broker
+      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
+      KAFKA_CFG_LISTENERS: BROKER://:9092, LOCALHOST://:9083
+      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT, CONTROLLER:PLAINTEXT, LOCALHOST:PLAINTEXT
+      KAFKA_CFG_ADVERTISED_LISTENERS: BROKER://kafka-3:9092, LOCALHOST://localhost:9083
       KAFKA_BROKER_ID: 3
-      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
-      KAFKA_LISTENERS: DOCKER://:9092, LOCALHOST://:9083
-      KAFKA_ADVERTISED_LISTENERS: DOCKER://kafka-3:9092, LOCALHOST://localhost:9083
-      KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER
-      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER:PLAINTEXT, LOCALHOST:PLAINTEXT
-      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
-      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "false"
+      KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 0@kafka-0:9092
+      ALLOW_PLAINTEXT_LISTENER: 'yes'
+      KAFKA_CFG_INTER_BROKER_LISTENER_NAME: BROKER
+      KAFKA_CFG_OFFSETS_TOPIC_REPLICATION_FACTOR: 3
+      KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: "false"
     ports:
       - 9083:9083
     depends_on:
-      - zookeeper
+      - kafka-0
 
   setup:
     image: juplo/toolbox
@@ -68,6 +92,10 @@ services:
         kafka-topics --bootstrap-server kafka:9092 --create --topic test --partitions 2 --replication-factor 3 --config min.insync.replicas=2
         kafka-topics --bootstrap-server kafka:9092 --describe --topic test
       "
+    depends_on:
+      - kafka-1
+      - kafka-2
+      - kafka-3
 
   cli:
     image: juplo/toolbox