Updating a Kafka environment to use KRaft (Kafka Raft) mode instead of ZooKeeper involves several steps. KRaft mode is a new feature in Apache Kafka that allows Kafka brokers to manage metadata directly, eliminating the need for ZooKeeper. This transition involves setting up a new Kafka cluster in KRaft mode, migrating data, and updating configurations.

Prerequisites

  1. Apache Kafka 2.8.0 or later: KRaft mode is available starting from Kafka 2.8.0, but it's stable for production in Kafka 3.0.0 and later.
  2. Backup Data: Ensure you have a backup of your existing Kafka data and configurations.

Steps to Update Kafka Environment to Use KRaft

Step 1: Prepare Your Environment

  1. Download and Install Kafka:

    wget <https://downloads.apache.org/kafka/3.2.0/kafka_2.13-3.2.0.tgz>
    tar -xzf kafka_2.13-3.2.0.tgz
    cd kafka_2.13-3.2.0
    
    

Step 2: Configure KRaft Mode

  1. Create a New Configuration File:

    # Basic Kafka settings
    process.roles=broker,controller
    node.id=1
    controller.quorum.voters=1@localhost:9093
    listeners=PLAINTEXT://localhost:9092,CONTROLLER://localhost:9093
    inter.broker.listener.name=PLAINTEXT
    log.dirs=/tmp/kraft-combined-logs
    
    
  2. Additional Configuration:

    log.retention.hours=168
    num.partitions=1
    default.replication.factor=1
    min.insync.replicas=1
    
    

Step 3: Format the Storage for KRaft

  1. Format the Kafka Storage:

    bin/kafka-storage.sh format -t <uuid> -c config/server.properties
    
    
    uuidgen
    
    

Step 4: Start Kafka in KRaft Mode

  1. Start the Kafka Broker:

    bin/kafka-server-start.sh config/server.properties
    
    

Step 5: Migrate Data and Clients

  1. Reconfigure Clients:
  2. Migrate Topics and Data:
  3. Verify Data Migration:

Step 6: Decommission the Old Cluster

  1. Shutdown Old Brokers: