我正在使用minikube在kubernetes部署kafka/zookeeper。下面是我的yaml文件:
##################################
# Setup Zookeeper Deployment
##################################
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: zookeeper
name: zookeeper
spec:
replicas: 1
template:
metadata:
labels:
app: zookeeper
spec:
containers:
- image: wurstmeister/zookeeper
# imagePullPolicy: Always
name: zookeeper
ports:
- containerPort: 2181
##################################
# Setup Zookeeper Service
##################################
---
apiVersion: v1
kind: Service
metadata:
labels:
app: zookeeper-service
name: zookeeper-service
spec:
type: NodePort
ports:
- name: zookeeper-port
port: 2181
nodePort: 30181
targetPort: 2181
selector:
app: zookeeper
---
##################################
# Setup Kafka service
##################################
apiVersion: v1
kind: Service
metadata:
labels:
app: kafka-service
name: kafka-service
spec:
type: NodePort
ports:
- name: kafka-port
port: 9092
nodePort: 30092
targetPort: 9092
selector:
app: kafka
---
##################################
# Setup Kafka Broker Deployment
##################################
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: kafka
name: kafka
spec:
replicas: 1
template:
metadata:
labels:
app: kafka
spec:
containers:
- env:
- name: KAFKA_ADVERTISED_HOST_NAME
value: 192.168.99.100
- name: KAFKA_ADVERTISED_PORT
value: "30092"
- name: KAFKA_BROKER_ID
value: "1"
- name: KAFKA_ZOOKEEPER_CONNECT
value: 192.168.99.100:30181
- name: KAFKA_ADVERTISED_LISTENERS
value: "PLAINTEXT://192.168.99.100:30092"
# - name: KAFKA_LISTENERS
# value: "PLAINTEXT://192.168.99.100:9092"
- name: KAFKA_CREATE_TOPICS
value: "vignesh-topic:1:1"
- name: LOG4J_LOGGER_KAFKA_AUTHORIZER_LOGGER
value: "DEBUG"
image: wurstmeister/kafka
#imagePullPolicy: Always
name: kafka
ports:
- containerPort: 9092
我已经使用minikube和below命令在本地机器kubernetes中成功地创建了部署/服务。
kubectl create -f kafka.yml
我在Kafka豆荚里导航过,我可以用下面的命令创建一个主题,
./bin/kafka-topics.sh --create --zookeeper 192.168.99.100:30181 --replication-factor 1 --partitions 1 --topic test-topic
但是,当我尝试向主题(testtopic)发送消息时,系统抛出以下错误。
笔记
当我运行netstat-tunap时,端口30092和30181都显示已建立。
我不知道我错过了什么。请帮我往前走。
谢谢你的帮助。
1条答案
按热度按时间lnvxswe21#
感谢@soheilpourbafrani和@cricket\u 007的帮助!我已经找到了解决上述问题的方法。
一旦我在窗口powershell中运行了下面的命令,kafka就正常启动了,并且能够从节点应用程序和kafka工具与之通信。
参考资料:更新版本的minikube不允许pods使用自己的服务