Skip to content

Commit 690ca08

Browse files
authored
remove usage of /etc/hosts (#29)
* first try * travis fixes * bring back addon * better interpolation * increase compose version * use KAFKA_ADVERTISED_LISTENERS * all stack changes * compose v2.1 * correct indentation * fixes in environment variables and kafka-rest and kafka-schema registry config
1 parent 5dfc466 commit 690ca08

File tree

8 files changed

+74
-100
lines changed

8 files changed

+74
-100
lines changed

.travis.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22
# it is not related to your Kafka Streams learning
33
sudo: required
44

5+
env:
6+
- DOCKER_HOST_IP=127.0.0.1
7+
# - DOCKER_HOST_IP=192.168.99.100
8+
59
services:
610
- docker
711

812
addons:
9-
hosts:
10-
- kafka1
11-
- kafka2
12-
- kafka3
13-
- zoo1
14-
- zoo2
15-
- zoo3
16-
- kafka-schema-registry
17-
- kafka-schema-registry-ui
18-
- kafka-rest-proxy
19-
- kafka-topics-ui
20-
- kafka-connect-ui
21-
- zoonavigator-web
22-
- zoonavigator-api
23-
2413
# install the kafka binaries
2514
apt:
2615
sources:

README.md

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
# kafka-stack-docker-compose
55

6-
This replicates as well as possible real deployment configurations, where you have your zookeeper servers and kafka servers actually all distinct from each other. This solves all the networking hurdles that comes with docker-compose, and is compatible cross platform. It only requires an update to your host files.
6+
This replicates as well as possible real deployment configurations, where you have your zookeeper servers and kafka servers actually all distinct from each other. This solves all the networking hurdles that comes with Docker and docker-compose, and is compatible cross platform.
7+
8+
[UPDATE]: No /etc/hosts file changes are necessary anymore. Explanations at: https://rmoff.net/2018/08/02/kafka-listeners-explained/
79

810
## Stack version
911

@@ -19,52 +21,29 @@ This replicates as well as possible real deployment configurations, where you ha
1921

2022
# Requirements
2123

22-
## Host File changes
23-
24-
See https://support.rackspace.com/how-to/modify-your-hosts-file/ to detailed instructions on how to modify your host files.
24+
## Docker
2525

26-
If you are using Docker for Mac >= 1.12, Docker for Linux, or Docker for Windows 10, then please add the following lines to `/etc/hosts` or `C:\Windows\System32\Drivers\etc\hosts`:
26+
Please export your environment before starting the stack:
2727
```
28-
127.0.0.1 kafka1
29-
127.0.0.1 kafka2
30-
127.0.0.1 kafka3
31-
127.0.0.1 zoo1
32-
127.0.0.1 zoo2
33-
127.0.0.1 zoo3
34-
127.0.0.1 kafka-schema-registry
35-
127.0.0.1 kafka-schema-registry-ui
36-
127.0.0.1 kafka-rest-proxy
37-
127.0.0.1 kafka-topics-ui
38-
127.0.0.1 kafka-connect-ui
39-
127.0.0.1 zoonavigator-web
40-
127.0.0.1 zoonavigator-api
28+
export DOCKER_HOST_IP=127.0.0.1
4129
```
30+
(that's the default value and you actually don't need to do a thing)
4231

32+
## Docker-Toolbox
4333
If you are using Docker for Mac <= 1.11, or Docker Toolbox for Windows
4434
(your docker machine IP is usually `192.168.99.100`)
45-
Please add the following lines to `/etc/hosts` or `C:\Windows\System32\Drivers\etc\hosts`:
35+
36+
Please export your environment before starting the stack:
4637
```
47-
192.168.99.100 kafka1
48-
192.168.99.100 kafka2
49-
192.168.99.100 kafka3
50-
192.168.99.100 zoo1
51-
192.168.99.100 zoo2
52-
192.168.99.100 zoo3
53-
192.168.99.100 kafka-schema-registry
54-
192.168.99.100 kafka-schema-registry-ui
55-
192.168.99.100 kafka-rest-proxy
56-
192.168.99.100 kafka-topics-ui
57-
192.168.99.100 kafka-connect-ui
58-
192.168.99.100 zoonavigator-web
59-
192.168.99.100 zoonavigator-api
38+
export DOCKER_HOST_IP=192.168.99.100
6039
```
6140

6241
## Single Zookeeper / Single Kafka
6342

6443
This configuration fits most development requirements.
6544

66-
- Zookeeper will be available at `zoo1:2181`
67-
- Kafka will be available at `kafka1:9092`
45+
- Zookeeper will be available at `$DOCKER_HOST_IP:2181`
46+
- Kafka will be available at `$DOCKER_HOST_IP:9092`
6847

6948

7049
Run with:
@@ -77,8 +56,8 @@ docker-compose -f zk-single-kafka-single.yml down
7756

7857
If you want to have two brokers and experiment with replication / fault-tolerance.
7958

80-
- Zookeeper will be available at `zoo1:2181`
81-
- Kafka will be available at `kafka1:9092,kafka2:9093,kafka3:9094`
59+
- Zookeeper will be available at `$DOCKER_HOST_IP:2181`
60+
- Kafka will be available at `$DOCKER_HOST_IP:9092,$DOCKER_HOST_IP:9093,$DOCKER_HOST_IP:9094`
8261

8362

8463
Run with:
@@ -91,22 +70,22 @@ docker-compose -f zk-single-kafka-multiple.yml down
9170

9271
If you want to have three zookeeper and experiment with zookeeper fault-tolerance.
9372

94-
- Zookeeper will be available at `zoo1:2181,zoo2:2182,zoo3:2183`
95-
- Kafka will be available at `kafka1:9092`
73+
- Zookeeper will be available at `$DOCKER_HOST_IP:2181,$DOCKER_HOST_IP:2182,$DOCKER_HOST_IP:2183`
74+
- Kafka will be available at `$DOCKER_HOST_IP:9092`
9675

9776
Run with:
9877
```
9978
docker-compose -f zk-multiple-kafka-single.yml up
100-
docker-compose -f zk-multiple-kafka-single.yml down
79+
docker-compose -f ²zk-multiple-kafka-single.yml down
10180
```
10281

10382

10483
## Multiple Zookeeper / Multiple Kafka
10584

10685
If you want to have three zookeeper and two kafka brokers to experiment with production setup.
10786

108-
- Zookeeper will be available at `zoo1:2181,zoo2:2182,zoo3:2183`
109-
- Kafka will be available at `kafka1:9092,kafka2:9093,kafka3:9094`
87+
- Zookeeper will be available at `$DOCKER_HOST_IP:2181,$DOCKER_HOST_IP:2182,$DOCKER_HOST_IP:2183`
88+
- Kafka will be available at `$DOCKER_HOST_IP:9092,$DOCKER_HOST_IP:9093,$DOCKER_HOST_IP:9094`
11089

11190
Run with:
11291
```
@@ -117,15 +96,15 @@ docker-compose -f zk-multiple-kafka-multiple.yml down
11796

11897
## Full stack
11998

120-
- Single Zookeeper: `zoo1:2181`
121-
- Single Kafka: `kafka1:9092`
122-
- Kafka Schema Registry: `kafka-schema-registry:8081`
123-
- Kafka Schema Registry UI: `kafka-schema-registry-ui:8001`
124-
- Kafka Rest Proxy: `kafka-rest-proxy:8082`
125-
- Kafka Topics UI: `kafka-topics-ui:8000`
126-
- Kafka Connect: `kafka-connect:8083`
127-
- Kafka Connect UI: `kafka-connect-ui:8003`
128-
- Zoonavigator Web: `zoonavigator-web:8004`
99+
- Single Zookeeper: `$DOCKER_HOST_IP:2181`
100+
- Single Kafka: `$DOCKER_HOST_IP:9092`
101+
- Kafka Schema Registry: `$DOCKER_HOST_IP:8081`
102+
- Kafka Schema Registry UI: `$DOCKER_HOST_IP:8001`
103+
- Kafka Rest Proxy: `$DOCKER_HOST_IP:8082`
104+
- Kafka Topics UI: `$DOCKER_HOST_IP:8000`
105+
- Kafka Connect: `$DOCKER_HOST_IP:8083`
106+
- Kafka Connect UI: `$DOCKER_HOST_IP:8003`
107+
- Zoonavigator Web: `$DOCKER_HOST_IP:8004`
129108

130109

131110
Run with:

full-stack.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
zoo1:
@@ -22,8 +22,9 @@ services:
2222
ports:
2323
- "9092:9092"
2424
environment:
25-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
26-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka1:9092"
25+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092
26+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
27+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
2728
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
2829
KAFKA_BROKER_ID: 1
2930
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
@@ -36,11 +37,10 @@ services:
3637
kafka-schema-registry:
3738
image: confluentinc/cp-schema-registry:4.1.0
3839
hostname: kafka-schema-registry
39-
restart: unless-stopped
4040
ports:
4141
- "8081:8081"
4242
environment:
43-
SCHEMA_REGISTRY_KAFKASTORE_CONNECTION_URL: zoo1:2181
43+
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: PLAINTEXT://kafka1:19092
4444
SCHEMA_REGISTRY_HOST_NAME: kafka-schema-registry
4545
SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8081
4646
depends_on:
@@ -64,11 +64,11 @@ services:
6464
ports:
6565
- "8082:8082"
6666
environment:
67-
KAFKA_REST_ZOOKEEPER_CONNECT: zoo1:2181
67+
# KAFKA_REST_ZOOKEEPER_CONNECT: zoo1:2181
6868
KAFKA_REST_LISTENERS: http://0.0.0.0:8082/
6969
KAFKA_REST_SCHEMA_REGISTRY_URL: http://kafka-schema-registry:8081/
7070
KAFKA_REST_HOST_NAME: kafka-rest-proxy
71-
KAFKA_REST_BOOTSTRAP_SERVERS: kafka1:9092
71+
KAFKA_REST_BOOTSTRAP_SERVERS: PLAINTEXT://kafka1:19092
7272
depends_on:
7373
- zoo1
7474
- kafka1
@@ -94,7 +94,7 @@ services:
9494
ports:
9595
- "8083:8083"
9696
environment:
97-
CONNECT_BOOTSTRAP_SERVERS: "kafka1:9092"
97+
CONNECT_BOOTSTRAP_SERVERS: "kafka1:19092"
9898
CONNECT_REST_PORT: 8083
9999
CONNECT_GROUP_ID: compose-connect-group
100100
CONNECT_CONFIG_STORAGE_TOPIC: docker-connect-configs
@@ -140,12 +140,10 @@ services:
140140
- zoonavigator-api
141141
depends_on:
142142
- zoonavigator-api
143-
restart: unless-stopped
144143

145144
zoonavigator-api:
146145
image: elkozmon/zoonavigator-api:0.4.0
147146
environment:
148147
SERVER_HTTP_PORT: 9000
149-
restart: unless-stopped
150148
depends_on:
151149
- zoo1

test.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ kafka_tests(){
3636
echo "Testing Kafka"
3737
topic="testtopic"
3838
if grep -q kafka3 $1; then replication_factor="3"; else replication_factor="1"; fi
39-
for i in 1 2 3 4 5; do echo "trying to create test topic" && kafka-topics --create --topic $topic --replication-factor $replication_factor --partitions 12 --zookeeper localhost:2181 && break || sleep 5; done
40-
for x in {1..100}; do echo $x; done | kafka-console-producer --broker-list localhost:9092 --topic $topic
41-
rows=`kafka-console-consumer --bootstrap-server localhost:9092 --topic $topic --from-beginning --timeout-ms 2000 | wc -l`
42-
# rows=`kafkacat -C -b localhost:9092 -t $topic -o beginning -e | wc -l `
39+
for i in 1 2 3 4 5; do echo "trying to create test topic" && kafka-topics --create --topic $topic --replication-factor $replication_factor --partitions 12 --zookeeper $DOCKER_HOST_IP:2181 && break || sleep 5; done
40+
for x in {1..100}; do echo $x; done | kafka-console-producer --broker-list $DOCKER_HOST_IP:9092 --topic $topic
41+
rows=`kafka-console-consumer --bootstrap-server $DOCKER_HOST_IP:9092 --topic $topic --from-beginning --timeout-ms 2000 | wc -l`
42+
# rows=`kafkacat -C -b $DOCKER_HOST_IP:9092 -t $topic -o beginning -e | wc -l `
4343
if [ "$rows" != "100" ]; then
44-
kafka-console-consumer --bootstrap-server localhost:9092 --topic test-topic --from-beginning --timeout-ms 2000 | wc -l
44+
kafka-console-consumer --bootstrap-server $DOCKER_HOST_IP:9092 --topic test-topic --from-beginning --timeout-ms 2000 | wc -l
4545
exit 1
4646
else
4747
echo "Kafka Test Success"

zk-multiple-kafka-multiple.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
zoo1:
@@ -47,8 +47,9 @@ services:
4747
ports:
4848
- "9092:9092"
4949
environment:
50-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
51-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka1:9092"
50+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092
51+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
52+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
5253
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181,zoo2:2182,zoo3:2183"
5354
KAFKA_BROKER_ID: 1
5455
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
@@ -65,8 +66,9 @@ services:
6566
ports:
6667
- "9093:9093"
6768
environment:
68-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
69-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka2:9093"
69+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka2:19093,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9093
70+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
71+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
7072
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181,zoo2:2182,zoo3:2183"
7173
KAFKA_BROKER_ID: 2
7274
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
@@ -83,8 +85,9 @@ services:
8385
ports:
8486
- "9094:9094"
8587
environment:
86-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
87-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka3:9094"
88+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka3:19094,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9094
89+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
90+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
8891
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181,zoo2:2182,zoo3:2183"
8992
KAFKA_BROKER_ID: 3
9093
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"

zk-multiple-kafka-single.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
zoo1:
@@ -47,8 +47,9 @@ services:
4747
ports:
4848
- "9092:9092"
4949
environment:
50-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
51-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka1:9092"
50+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092
51+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
52+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
5253
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
5354
KAFKA_BROKER_ID: 1
5455
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"

zk-single-kafka-multiple.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
zoo1:
@@ -20,8 +20,9 @@ services:
2020
ports:
2121
- "9092:9092"
2222
environment:
23-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
24-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka1:9092"
23+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092
24+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
25+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
2526
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
2627
KAFKA_BROKER_ID: 1
2728
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
@@ -36,8 +37,9 @@ services:
3637
ports:
3738
- "9093:9093"
3839
environment:
39-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
40-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka2:9093"
40+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka2:19093,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9093
41+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
42+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
4143
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
4244
KAFKA_BROKER_ID: 2
4345
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"
@@ -53,8 +55,9 @@ services:
5355
ports:
5456
- "9094:9094"
5557
environment:
56-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
57-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka3:9094"
58+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka3:19094,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9094
59+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
60+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
5861
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
5962
KAFKA_BROKER_ID: 3
6063
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"

zk-single-kafka-single.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
zoo1:
@@ -20,8 +20,9 @@ services:
2020
ports:
2121
- "9092:9092"
2222
environment:
23-
# add the entry "127.0.0.1 kafka1" to your /etc/hosts file
24-
KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka1:9092"
23+
KAFKA_ADVERTISED_LISTENERS: LISTENER_DOCKER_INTERNAL://kafka1:19092,LISTENER_DOCKER_EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092
24+
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_DOCKER_INTERNAL:PLAINTEXT,LISTENER_DOCKER_EXTERNAL:PLAINTEXT
25+
KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_DOCKER_INTERNAL
2526
KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181"
2627
KAFKA_BROKER_ID: 1
2728
KAFKA_LOG4J_LOGGERS: "kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO"

0 commit comments

Comments
 (0)