错误Kafka无法在Kubernetes上连接Zookeeper(单节点)

时间:2018-12-18 11:25:58

标签: docker kubernetes apache-kafka apache-zookeeper

我在kubernetes 单节点 上运行kafka和zookeeper时遇到问题,我在我的笔记本电脑上进行了测试,并且可以正常工作,但我在私有计算机上运行服务器在kafka pod中显示错误,并且我不知道私有服务器上的网络设置

我使用kompose将docker-compose文件转换为k8s yaml文件

  

zoo1:名称解析暂时失败

如何解决该错误?

谢谢

我的部署和服务Yaml文件

kafka1-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: kafka1
  name: kafka1
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: kafka1
    spec:
      containers:
      - env:
        - name: KAFKA_ADVERTISED_LISTENERS
          value: PLAINTEXT://kafka1:9092
        - name: KAFKA_BROKER_ID
          value: "1"
        - name: KAFKA_LOG4J_LOGGERS
          value: kafka.controller=INFO,kafka.producer.async.DefaultEventHandler=INFO,state.change.logger=INFO
        - name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
          value: "1"
        - name: KAFKA_ZOOKEEPER_CONNECT
          value: zoo1:2181
        image: confluentinc/cp-kafka:4.0.0
        name: kafka1
        ports:
        - containerPort: 9092
        resources: {}
      hostname: kafka1
      restartPolicy: Always
status: {}

kafka1-service.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: kafka1
  name: kafka1
spec:
  ports:
  - name: "9092"
    port: 9092
    targetPort: 9092
  selector:
    io.kompose.service: kafka1
status:
  loadBalancer: {}

zoo1-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: zoo1
  name: zoo1
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: zoo1
    spec:
      containers:
      - env:
        - name: ZOO_MY_ID
          value: "1"
        - name: ZOO_PORT
          value: "2181"
        - name: ZOO_SERVERS
          value: server.1=zoo1:2888:3888
        image: zookeeper:3.4.9
        name: zoo1
        ports:
        - containerPort: 2181
        resources: {}
      hostname: zoo1
      restartPolicy: Always
status: {}

zoo1-service.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.16.0 (0c01309)
  creationTimestamp: null
  labels:
    io.kompose.service: zoo1
  name: zoo1
spec:
  ports:
  - name: "2181"
    port: 2181
    targetPort: 2181
  selector:
    io.kompose.service: zoo1
status:
  loadBalancer: {}

1 个答案:

答案 0 :(得分:0)

您必须为kafla和zookeeper创建无头服务

我建议使用合掌舵图在kubernetes中使用kafka,您可以找到他们如何创建无头服务。

什么是日志?到底是怎么回事?

希望有帮助!