Skip to content

Commit 49649e1

Browse files
committed
Merge branch 'increase-replication-factor' into ops-jobs
motivated by #140
2 parents e6a7aec + 4257128 commit 49649e1

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

maintenance/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ Create the `preferred-replica-election-job.yml` resource, after deleting any pre
2020
_-- Neha Narkhede, Gwen Shapira, and Todd Palino. ”Kafka: The Definitive Guide”_
2121

2222
Use the `reassign-paritions-job.yml`, after editing `TOPICS` and `BROKERS`.
23+
24+
## Increase a topic's replication factor
25+
26+
See https://github.com/Yolean/kubernetes-kafka/pull/140
27+
28+
Use the `replication-factor-increase-job.yml`, after editing `TOPICS` and `BROKERS`.
29+
30+
The affected topics may end up without a preferred replica. See above to fix that,
31+
or to affect only your selected topics use [Kafka Manager's](https://github.com/Yolean/kubernetes-kafka/pull/83) topic screen,
32+
Generate Partition Assignments followed by Reassigned Partitions.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: replication-factor-increase
5+
namespace: kafka
6+
spec:
7+
template:
8+
metadata:
9+
name: replication-factor-increase
10+
spec:
11+
containers:
12+
- name: kafka
13+
image: solsson/kafka:1.0.0@sha256:17fdf1637426f45c93c65826670542e36b9f3394ede1cb61885c6a4befa8f72d
14+
env:
15+
- name: ZOOKEEPER
16+
value: zookeeper.kafka:2181
17+
# the following must be edited per job
18+
- name: TOPICS
19+
value: ""
20+
- name: BROKERS
21+
value: 0,1,2
22+
command:
23+
- /bin/bash
24+
- -ce
25+
- >
26+
if [ -z "$TOPICS" ]; then
27+
echo "Please set the TOPICS env (comma-separated) and re-create the job"
28+
tail -f /dev/null
29+
fi
30+
31+
echo '{"topics":[' > /tmp/reassign-topics.json;
32+
echo -n ' {"topic":"' >> /tmp/reassign-topics.json;
33+
echo -n $TOPICS | sed 's/,/"},\n {"topic":"/g' >> /tmp/reassign-topics.json;
34+
echo '"}' >> /tmp/reassign-topics.json;
35+
echo ']}' >> /tmp/reassign-topics.json;
36+
37+
echo "# reassign-topics.json";
38+
cat /tmp/reassign-topics.json;
39+
40+
./bin/kafka-reassign-partitions.sh
41+
--zookeeper=$ZOOKEEPER
42+
--generate
43+
--topics-to-move-json-file=/tmp/reassign-topics.json
44+
--broker-list=$BROKERS > /tmp/generated.txt;
45+
46+
tail -n 1 /tmp/generated.txt > /tmp/proposed-reassignment.json;
47+
48+
sleep 1;
49+
echo "# proposed-reassignment.json";
50+
cat /tmp/proposed-reassignment.json;
51+
52+
sed -i 's/"replicas":\[.\]/"replicas":[0,1,2]/g' /tmp/proposed-reassignment.json;
53+
sed -i 's/,"log_dirs":\["any"\]//g' /tmp/proposed-reassignment.json;
54+
echo "# proposed-reassignment.json modified to affect replication factor";
55+
cat /tmp/proposed-reassignment.json;
56+
57+
echo "# Triggering kafka-reassign-partitions.sh"
58+
./bin/kafka-reassign-partitions.sh
59+
--zookeeper=$ZOOKEEPER
60+
--execute
61+
--reassignment-json-file=/tmp/proposed-reassignment.json;
62+
63+
echo "# Reassignment exited. Upon success you may want to run preferred-replica-election."
64+
restartPolicy: Never
65+
backoffLimit: 3

0 commit comments

Comments
 (0)