我在gke上设置kafka时遇到困难,想知道设置它的最佳方法吗?

时间:2019-05-22 14:52:00

标签: kubernetes apache-kafka google-kubernetes-engine

我试图使用statefulset在gke中的群集中部署zookeeper和Kafka服务器,但是Kafka和zookeeper之间的通信失败,并在日志中显示错误消息。我想知道在kubernetes中设置Kafka的最简单方法是什么。

我尝试了以下配置,但我发现Kafka无法与Zookeeper通信,但我不确定为什么?我知道我可能需要无头的服务,因为通讯是由Kafka和Zookeeper自己处理的。

对于Zookeeper

let scene = document.querySelector("a-scene")  
scene.camera.far = 3 // default is 1000 afaik

对于Kafka

apiVersion: v1
kind: Service
metadata:
  name: zookeeper
spec:
  type: LoadBalancer
  selector:
    app: zookeeper
  ports:
  - port: 2181
    targetPort: client
    name: zk-port
  - port: 2888
    targetPort: leader
    name: zk-leader
  - port: 3888
    targetPort: election
    name: zk-election
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: zookeeper
spec:
  replicas: 3
  selector:
    matchLabels:
      app: zookeeper
  serviceName: zookeeper
  podManagementPolicy: Parallel
  template:
    metadata:
      labels:
        app: zookeeper
    spec:
      containers:
        - name: zk-pod
          image: zookeeper:latest
          imagePullPolicy: Always
          ports:
            - name: client
              containerPort: 2181
            - name: leader
              containerPort: 2888
            - name: election
              containerPort: 3888
          env:
            - name: ZOO_MY_ID
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: ZOO_TICK_TIME
              value: "2000"
            - name: ZOO_INIT_LIMIT
              value: "5"
            - name: ZOO_SYNC_LIMIT
              value: "2"
            - name: ZOO_SERVERS
              value: zookeeper:2888:3888

我希望能够向某个主题发送消息并能够回读它们。我一直在使用kafkacat来测试连接。

1 个答案:

答案 0 :(得分:0)

这是Official Kubernetes Documentation about StateFulsets中指定的限制之一,即

  
      
  • StatefulSet当前需要无头服务来负责Pod的网络标识。您负责创建此服务。
  •   

因此,正如您提到的,您需要Headless Service,并且可以轻松地将无头服务yaml添加到您的两个StatefulSet的配置顶部,如下所示:

apiVersion: v1
kind: Service
metadata:
  name: zookeeper
  labels:
    app: zookeeper
spec:
  ports:
  - port: 2181 
    name: someport
  clusterIP: None
  selector:
    app: zookeeper

希望有帮助!