kafka需要zookeeper的支持,我们可以使用docker-compose简单的部署一个环境,在部署时,kafka需要我们为它配置一个hostname,这个名称是每个kafka节点(broken)的名称,也是很容易被忽视的地方,通过kafka客户端工具可以看到你当前部署kafka时的hostsname,在部署java时,你的主机也需要配置这个host.
部署一个kafka
docker-compose实现
version: '2'
services:
zookeeper:
image: wurstmeister/zookeeper
hostname: zookeeper1
network_mode: bridge
ports:
- "2181:2181"
kafka:
image: wurstmeister/kafka:2.11-0.11.0.3
hostname: kafka1
network_mode: bridge
links:
- zookeeper
ports:
- "9092:9092" #表示宿主机的端口为随机,这样方便使用docker-compose scale 进行扩容
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://:9092
KAFKA_LISTENERS: PLAINTEXT://:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
部署一个应用,使用k8s配置容器hosts
spec:
template:
spec:
hostAliases:
- ip: "192.168.60.146"
hostnames: ["kafka1"]