Cluster Operations
Reassigning partitions, adding brokers, changing configs, and upgrading
Day-to-day Kafka operations are mostly about moving data safely: when a broker is added, removed, or overloaded, partitions have to move, and moving partitions means copying data across the network. The book's Administering Kafka chapter covers the admin APIs; here's the workflow.
Partition reassignment
kafka-reassign-partitions.sh moves replicas between brokers in three
steps: generate a plan, execute it, verify it.
Run on this cluster with a topic whose replicas were only on brokers 1 and 2:
kafka-topics.sh $B --create --topic events --replica-assignment 1:2,1:2,2:1
Partition: 0 Leader: 1 Replicas: 1,2
Partition: 1 Leader: 1 Replicas: 1,2
Partition: 2 Leader: 2 Replicas: 2,1
# 1. generate: spread it across all three brokers
echo '{"topics":[{"topic":"events"}],"version":1}' > /tmp/t.json
kafka-reassign-partitions.sh $B --topics-to-move-json-file /tmp/t.json \
--broker-list 1,2,3 --generate | tail -1 > /tmp/plan.json
# 2. execute, with a replication throttle so the copy can't swamp the network
kafka-reassign-partitions.sh $B --reassignment-json-file /tmp/plan.json --execute --throttle 50000000
The inter-broker throttle limit was set to 50000000 B/s
Successfully started partition reassignments for events-0,events-1,events-2
# 3. verify: reports progress, and removes the throttles once everything is done
kafka-reassign-partitions.sh $B --reassignment-json-file /tmp/plan.json --verify
Reassignment of partition events-2 is completed.
Clearing broker-level throttles on brokers 1,2,3
Clearing topic-level throttles on topic events
Partition: 0 Leader: 1 Replicas: 3,1 Isr: 1,3
Partition: 1 Leader: 1 Replicas: 1,2 Isr: 1,2
Partition: 2 Leader: 2 Replicas: 2,3 Isr: 2,3During a reassignment, the new replica fetches the whole partition from the leader, joins the ISR, and only then is the old replica removed. The partition is never under-replicated by design.
Always run --verify until it reports completion. It's the step that
removes the throttle. Forget it and replication on those brokers
stays capped at the throttle rate, and the next broker failure takes far
longer to recover from. Also, --generate can't place more replicas than
there are brokers in --broker-list: asking to move an RF-3 topic onto 2
brokers fails outright.
After the move, partition 0's preferred leader is 3 but its leader is still 1. Finish with a preferred leader election.
Adding a broker
A new broker gets no data automatically: existing partitions stay where they are, and only new topics use it. To use it:
- Start it with a new
node.idand the sameCLUSTER_ID. - Reassign some partitions onto it (generate with a broker list that includes it).
- Run a preferred leader election.
Tools like Cruise Control automate the "which partitions should move" decision based on load.
Removing a broker
The reverse: reassign everything off it, verify, then shut it down. In
KRaft, also unregister it:
kafka-cluster.sh unregister --bootstrap-server ... --id 4.
Changing configuration
Many settings are dynamic, changeable at runtime without a restart:
Others (listeners, process.roles, log.dirs) need a rolling restart,
one broker at a time, waiting for zero under-replicated partitions between
each (see Broker Failures).
Upgrades
Kafka upgrades are rolling restarts with one extra step:
- Read the upgrade notes for every version you're crossing.
- Upgrade brokers (and controllers) one at a time to the new binary.
- Once every node runs the new version and the cluster is stable,
bump the feature level:
kafka-features.sh --bootstrap-server ... upgrade --metadata 4.3. - Clients can be upgraded independently; brokers support old protocol versions.
Until step 3, the cluster keeps the old metadata format, so you can still roll back the binaries. After it, you can't. That's the whole reason it's a separate, deliberate step.
Lab
- Reproduce the
eventsreassignment above, then run the preferred election and describe the topic. - Run the same reassignment without
--throttleon a topic with 50 MB of data, and compare how long it takes. - Change
retention.mson a topic dynamically and confirm with--describe. - Read
kafka-features.sh describe, and find where the currentmetadata.versionis shown.