It is worth checking the replication factor before modifying:

./path/to/kafka/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test-topic
Topic:test-topic        PartitionCount:2        ReplicationFactor:1     Configs:
        Topic: demo-topic       Partition: 0    Leader: 0       Replicas: 0     Isr: 0
        Topic: demo-topic       Partition: 1    Leader: 1       Replicas: 1     Isr: 1

It can be seen here that the replication factor is 1.

To update to a replication factor of e.g. 3 firstly create a json file with a new reassignment plan. Call it e.g. reassignment-plan.json:

{"version":1,
  "partitions":[
     {"topic":"demo-topic","partition":0,"replicas":[2,1,0]},
     {"topic":"demo-topic","partition":1,"replicas":[2,0,1]}
]}

Now pass this JSON file to Kafka reassign partitions tool script with –execute:

./path/to/kafka/bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file reassignment-plan.json --execute

Finally check the replication factor of the topic to confirm replication has been updated:

./path/to/kafka/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test-topic
Topic:test-topic	PartitionCount:2	ReplicationFactor:3	Configs:
	Topic: test-topic	Partition: 0	Leader: 2	Replicas: 2,1,0	Isr: 2,0,1
	Topic: test-topic	Partition: 1	Leader: 0	Replicas: 0,2,1	Isr: 0,2,1
Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: matt@linuxtutorial.co.uk.