apache-kafkadocker-composebitnamikraft

kafka kraft running in docker and windows wsl2


I'm trying to create a docker-compose with kafka kfrat but without success. I'm using bitnami image instead of confuentinc. Follow my docker compose:

version: "3.9"
services:
  controller:
    image: "bitnami/kafka:3.4.0"
    hostname: "controller"
    container_name: "controller"
    restart: "always"
    environment:
      BITNAMI_DEBUG: yes
      ALLOW_PLAINTEXT_LISTENER: yes
      KAFKA_ENABLE_KRAFT: yes
      KAFKA_KRAFT_CLUSTER_ID: "7f29c1ac-01b2-4012-82c7-6f1e8d24dcbf"
      KAFKA_CFG_PROCESS_ROLES: controller,broker
      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: CONTROLLER
      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT,BROKER_ONE:PLAINTEXT
      KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@controller:9092
      KAFKA_CFG_BROKER_ID: 1
      KAFKA_CFG_ADVERTISED_LISTENERS: BROKER_ONE://localhost:9093

    ports:
      - 9092:9092
    volumes:
      - controller_data:/bitnami/kafka
    networks:
      kafka_network:
        ipv4_address: 175.19.0.3

  broker_one:
    image: "bitnami/kafka:3.4.0"
    hostname: "broker_one"
    container_name: "broker_one"
    restart: "always"
    environment:
      BITNAMI_DEBUG: yes
      ALLOW_PLAINTEXT_LISTENER: yes
      KAFKA_ENABLE_KRAFT: yes
      KAFKA_KRAFT_CLUSTER_ID: "7f29c1ac-01b2-4012-82c7-6f1e8d24dcbf"
      KAFKA_CFG_PROCESS_ROLES: broker
      KAFKA_CFG_CONTROLLER_LISTENER_NAMES: BROKER_ONE
      KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: BROKER_ONE:PLAINTEXT,PLAINTEXT:PLAINTEXT
      KAFKA_CFG_BROKER_ID: 2
      KAFKA_CFG_CONTROLLER_QUORUM_VOTERS: 1@controller:9092
      KAFKA_CFG_LISTENERS: BROKER_ONE://:9094
      KAFKA_CFG_ADVERTISED_LISTENERS: BROKER_ONE://localhost:9093
    ports:
      - 9094:9094
    volumes:
      - controller_data:/bitnami/kafka
    networks:
      kafka_network:
        ipv4_address: 175.19.0.3

  kafka-ui:
    image: 'provectuslabs/kafka-ui'
    hostname: "kafka-ui"
    container_name: kafka-ui
    ports:
      - "9090:8080"
    environment:
      KAFKA_CLUSTERS_0_BOOTSTRAP_SERVERS: broker_controller:9092
      KAFKA_CLUSTERS_0_NAME: "7f29c1ac-01b2-4012-82c7-6f1e8d24dcbf"
      SERVER_PORT: 8080
    volumes:
      - broker_one_data:/bitnami/kafka
    networks:
      kafka_network:
        ipv4_address: 175.19.0.5
    depends_on:
      - broker_one
volumes:
  controller_data:
    name: "controller_data"
    driver: "local"
  broker_one_data:
    name: "broker_one_data"
    driver: "local"

the kafka controller just starts and stops. Is this the correct behavior?

and kafka broker restart after every 10 seconds with this:

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: The advertised.listeners config must not contain KRaft controller listeners from controller.listener.names when process.roles contains the broker role because Kafka clients that send requests via advertised listeners do not send requests to KRaft controllers -- they only send requests to KRaft brokers.


Solution

  • You appear to be trying to run a broker separate from a controller.

    This is an open issue in the Bitnami container