apache-kafkakraft

Kafka: Find Controller ID in a cluster using Kraft protocol


How to find the current controller ID, preferably using command-line, on a Kafka cluster which is using Kraft.

Kafka Version: 3.3


Solution

  • When using KRaft, a cluster no longer has a single controller. Instead, nodes in the cluster that are running with the "controller" role, all take part in the controller metadata quorum.

    The reason that tools are reporting seemingly random IDs is because of an intentional choice to return a random controller participant ID in the existing metadata APIs. This helps in distributing load equally on the nodes participating in the quorum.

    Underneath, the participants of the metadata quorum are maintaining a special topic that is replicated with the Raft consensus algorithm. This topic has a leader and you can get the leader ID of that topic. But it is important to note that this is not equal to the controller on a ZK-backed cluster, that role no longer exists when running with KRaft, and as mentioned is now instead a role shared by many nodes.

    You should be able to fetch the current leader ID of a cluster by requesting metadata for the __cluster_metadata topic, or as suggested in another answer by using the kafka-metadata-quorum script.