不能从Kubernetes外进入Kafka

a64a0gku  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(294)

我正试着在我的本地机器上从库伯内茨外访问Kafka。我正在使用spring应用程序生成一个主题的事件。这是我对Kafka的部署文件:

kind: Deployment
metadata:
  name: kafka-broker0
  labels:
    app: kafka
spec:
  replicas: 2
  selector:
    matchLabels:
      app: kafka
      id: "0"
  template:
    metadata:
      labels:
        app: kafka
        id: "0"
    spec:
      containers:
      - name: kafka
        image: wurstmeister/kafka
        ports:
        - containerPort: 9092
        env:
        - name: KAFKA_ADVERTISED_PORT
          value: "30718"
        - name: KAFKA_ADVERTISED_HOST_NAME
          value: 192.168.1.240
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: zoo1:2181
        - name: KAFKA_BROKER_ID
          value: "0"
        - name: KAFKA_CREATE_TOPICS
          value: LaunchScraper:1:1

和服务文件id:

kind: Service
metadata:
  name: kafka-services
  labels:
    name: kafka
spec:
  selector:
    app: kafka
    id: "0"
  ports:
    - protocol: TCP
      name: kafka-port
      port: 9092
  type: NodePort

我已经准备好在Kubernetes上建立一个Zookeeper吊舱了。我的spring boot应用程序显示此错误:

2020-09-25 23:56:29.123  WARN 44324 --- [ad | producer-1] org.apache.kafka.clients.NetworkClient   : [Producer clientId=producer-1] Connection to node -1 (/192.168.1.240:9092) could not be established. Broker may not be available.
ubof19bj

ubof19bj1#

似乎您的服务中没有修复节点端口。当你到达Kafka港输入的值时。同时将kafka\u播发的\u主机设置为k8s节点主机名/dns。
在你的服务规范中添加 nodePort: 30718ports 进入。然后在客户端中,尝试使用节点的地址或主机名在30718端口上进行连接
另外,如果您希望在生产环境中部署kafka,我建议您使用strimzi之类的操作符https://strimzi.io

相关问题