Deploy Apache Kafka Clusters
Domain 2, Deploy Apache Kafka clusters, tests capacity planning, metadata-mode selection, listener configuration and the mechanics of rolling deployment and expansion. The exam expects exact commands and ordering, not general installation advice.
Sizing and host layout
- Kafka relies on the OS page cache, so heap is usually modest (roughly 6–8 GB) and the remainder of RAM is left for caching. Very large heaps hurt GC pause times.
- Plan for disk throughput, not just capacity: replication multiplies writes by the replication factor, and consumers add read load.
- Use dedicated
log.dirsvolumes; JBOD gives capacity and parallelism, RAID gives simpler replacement but different failure semantics. Network-attached storage adds latency that shows up as fetch and produce delays.
KRaft versus ZooKeeper
- KRaft requires
process.roles,node.id,controller.quorum.votersandcontroller.listener.names. Storage is formatted once withkafka-storage.sh random-uuidandkafka-storage.sh format -t <uuid> -c server.properties; every node must use the same cluster ID. - Production clusters use dedicated controllers in an odd number (3 or 5); combined broker/controller mode is for development or small environments.
- ZooKeeper mode uses
zookeeper.connect, optionally with a chroot path.
Listeners and advertised addresses
listenersdefines bound interfaces;advertised.listenersdefines what clients and brokers are told to connect to. Advertised addresses must be resolvable and reachable by every client that will connect.- Keep an inter-broker listener separate from client listeners where security policies differ, and a distinct controller listener in KRaft.
listener.security.protocol.mapmust map every listener name to a protocol that matches its security configuration.
Rolling deployment and expansion
- Restart one broker at a time and wait until
UnderReplicatedPartitionsreturns to zero before continuing. - To add brokers, start them with unique
broker.id/node.idvalues, then generate a reassignment plan withkafka-reassign-partitions.sh --generate, execute it with--execute --throttle, and verify with--verify.
Worked example
A six-broker cluster must grow to eight. Each new node gets a unique node ID and matching advertised.listeners. A reassignment JSON is generated for selected topics, executed with a 50 MB/s throttle to protect client traffic, then verified. Leadership is balanced afterwards with a preferred-leader election.
Traps
- Leaving
advertised.listenersatlocalhost, which works on the host but fails for remote clients. - Duplicate
broker.id/node.idvalues, causing a broker to be rejected or to replace another. - Reformatting storage on a node that already holds log data.
- Using an even number of controllers, which weakens quorum fault tolerance.