spring 尝试连接到部署在本地k8上的本地kafka代理时,出现错误消息KafkaAdminClient

t3psigkw  于 2023-02-28  发布在  Spring
关注(0)|答案(1)|浏览(218)

我尝试在本地k8上部署kafka,然后我需要通过应用程序和使用偏移资源管理器连接到它
因此,我使用kubectl创建了zookeeper服务,并使用这个yml文件进行部署

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
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: zookeeper
  name: zookeeper
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zookeeper
  template:
    metadata:
      labels:
        app: zookeeper
    spec:
      containers:
        - image: wurstmeister/zookeeper
          imagePullPolicy: IfNotPresent
          name: zookeeper
          ports:
            - containerPort: 2181

然后,我使用这个yml创建了kafka服务和部署

apiVersion: v1
kind: Service
metadata:
  labels:
    app: kafka-service
  name: kafka-service
spec:
  type: NodePort
  ports:
    - name: kafka-port
      port: 9092
      nodePort: 30182
      targetPort: 9092
  selector:
    app: kafka-broker
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: kafka-broker
  name: kafka-broker
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kafka-broker
  template:
    metadata:
      labels:
        app: kafka-broker
    spec:
      hostname: kafka-broker
      containers:
        - env:
            - name: KAFKA_BROKER_ID
              value: "1"
            - name: KAFKA_ZOOKEEPER_CONNECT
              value: 10.97.29.226:2181
            - name: KAFKA_LISTENERS
              value: PLAINTEXT://:9092
            - name: KAFKA_ADVERTISED_LISTENERS
              value: PLAINTEXT://kafka-broker:9092
          image: wurstmeister/kafka
          imagePullPolicy: IfNotPresent
          name: kafka-broker
          ports:
            - containerPort: 9092

服务和部署都已创建并正在运行
但是,当我尝试使用偏移键工具连接到这个Kafka时,连接错误。如果我只定义这个页面

,连接成功,但在尝试查看Kafka主题时出错
错误讯息

然后我在高级页面添加borker描述,就像这样

但出现错误消息连接到群集时出错,无法创建新的KafkaAdminClient

vojdkbi0

vojdkbi01#

看起来您缺少代理配置,通常我在CI上运行Kafka时会从我的Docker组合中暴露以下配置

KAFKA_LISTENERS: 'LISTENER_INTERNAL://kafka:29092,LISTENER_HOST://:9092'
      KAFKA_ADVERTISED_LISTENERS: LISTENER_INTERNAL://kafka:29092,LISTENER_HOST://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: LISTENER_INTERNAL:PLAINTEXT,LISTENER_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: LISTENER_INTERNAL

当一些其他服务尝试在Docker合成集群内部连接时,它使用下面的配置

KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:29092
      KAFKA_CLUSTERS_0_ZOOKEEPER: zookeeper-kafka:2181

这也解释了https://www.confluent.io/blog/kafka-listeners-explained/我希望这能有所帮助

相关问题