ZooKeeper role (and KRaft replacement) in Kafka - Commands & Configuration
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-logs num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 log.retention.hours=168 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000 zookeeper.connect=
process.roles: Defines the roles this Kafka node will play, including broker and controller for KRaft mode.
node.id: Unique identifier for this Kafka node.
controller.quorum.voters: Defines the controller nodes and their IDs and addresses for quorum.
listeners: Network addresses for client and controller communication.
inter.broker.listener.name: Listener used for broker-to-broker communication.
log.dirs: Directory where Kafka stores logs.
zookeeper.connect: Empty because KRaft mode does not use ZooKeeper.
bin/kafka-server-start.sh config/kafka.properties
bin/kafka-topics.sh --bootstrap-server localhost:9092 --create --topic example-topic --partitions 3 --replication-factor 1
--bootstrap-server - Specifies the Kafka broker address to connect to.--create - Creates a new topic.--partitions - Sets the number of partitions for the topic.--replication-factor - Sets the replication factor for the topic.bin/kafka-topics.sh --bootstrap-server localhost:9092 --list--bootstrap-server - Specifies the Kafka broker address to connect to.--list - Lists all topics.If you remember nothing else from this pattern, remember: KRaft mode removes the need for ZooKeeper by embedding cluster metadata management inside Kafka itself.
Practice
Solution
Step 1: Understand ZooKeeper's purpose
ZooKeeper is used to manage coordination tasks like leader election and metadata storage in Kafka clusters.Step 2: Identify what ZooKeeper does not do
ZooKeeper does not store Kafka messages or act as a client or broker replacement.Final Answer:
To manage cluster coordination and metadata -> Option DQuick Check:
ZooKeeper = cluster coordination [OK]
- Thinking ZooKeeper stores Kafka messages
- Confusing ZooKeeper with Kafka brokers
- Assuming ZooKeeper acts as a client
Solution
Step 1: Identify KRaft configuration property
KRaft mode requires setting the process.roles property to include controller and broker roles.Step 2: Eliminate incorrect options
ZooKeeper-related settings like kafka.zk.enabled=true and zookeeper.connect=localhost:2181 are not for KRaft. kafka.broker.only=true is not a valid Kafka config.Final Answer:
set process.roles=controller,broker -> Option CQuick Check:
process.roles = controller,broker [OK]
- Confusing ZooKeeper settings with KRaft
- Using deprecated or invalid config keys
- Assuming KRaft disables brokers
process.roles=broker,controller node.id=1 controller.quorum.voters=1@localhost:9093
What is the role of this broker?
Solution
Step 1: Analyze process.roles value
The value 'broker,controller' means this node acts as both broker and controller.Step 2: Confirm node.id and quorum voters
node.id=1 and controller.quorum.voters=1@localhost:9093 confirm this node is part of the controller quorum.Final Answer:
It acts as both broker and controller -> Option AQuick Check:
process.roles includes both roles [OK]
- Ignoring multiple roles in process.roles
- Confusing node.id with role type
- Assuming controller.quorum.voters disables broker role
Solution
Step 1: Understand error context
KRaft mode requires 'controller.quorum.voters' to define controller nodes.Step 2: Identify missing or wrong config
If this setting is missing or wrong, Kafka cannot form the controller quorum, causing startup errors.Final Answer:
Missing or incorrect 'controller.quorum.voters' setting -> Option BQuick Check:
controller.quorum.voters required in KRaft [OK]
- Confusing ZooKeeper settings with KRaft
- Ignoring controller quorum config
- Assuming log.dirs causes quorum errors
Solution
Step 1: Understand migration requirements
Moving to KRaft requires configuring roles and controller quorum voters and migrating metadata from ZooKeeper.Step 2: Eliminate incorrect options
The other options do not perform a proper migration to KRaft or incorrectly suggest keeping or modifying ZooKeeper.Final Answer:
Configure 'process.roles' and 'controller.quorum.voters' and migrate metadata to KRaft -> Option AQuick Check:
Migration needs roles, quorum, and metadata move [OK]
- Skipping metadata migration step
- Trying to run ZooKeeper and KRaft simultaneously
- Misconfiguring controller quorum voters
Ready to prove it?
Pass the test and this pattern moves unknown
