Skip to content

Instantly share code, notes, and snippets.

@lazystone
Last active November 9, 2017 15:48
Show Gist options
  • Save lazystone/f18d459a9905fa4045b4726c950ca620 to your computer and use it in GitHub Desktop.
Save lazystone/f18d459a9905fa4045b4726c950ca620 to your computer and use it in GitHub Desktop.
Resizing a Kafka cluster
ZK_HOST=$(/usr/bin/consul watch -http-addr localhost:8500 -type service -service zookeeper-ms | jq -r "(.[]|(.Node.Address +\":\"+(.Service.Port|tostring)))" | xargs -i echo "{}" | paste -sd "," -)

kafka/bin/kafka-topics.sh --zookeeper $ZK_HOST --list > all_topics

grep -v deletion all_topics | tr '\n' ' ' | head --bytes -1 | jq -R 'split(" ") | reduce .[] as $topic ([]; . + [{"topic": $topic }]) | {"topics": . , "version": 1}' > all_topics.json

kafka/bin/kafka-reassign-partitions.sh --zookeeper $ZK_HOST --topics-to-move-json-file all_topics.json --broker-list "5062,51221,52218" --generate | tail -n 1 > reassignment.json

# Edit the reassignment.json file manually

kafka/bin/kafka-reassign-partitions.sh --zookeeper $ZK_HOST --reassignment-json-file reassignment.json --execute

kafka/bin/kafka-reassign-partitions.sh --zookeeper $ZK_HOST --reassignment-json-file reassignment.json --verify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment