Kubernetes服务无法正常工作与卡夫卡预期(Kubernetes service not wo

2019-10-28 08:31发布

我试图建立一个动物园管理员和卡夫卡作为单独Kubernetes部署/在共享命名空间豆荚。 我已经通过kubeadm bootstraped本地K8S 1.8用白布在我的Ubuntu沙...

对于动物园管理员,我使用的图像饲养员:3.4从hub.docker.com和我创建了一个Kubernetes部署和服务,在那里我揭露端口:2181 2888 3888服务名称是动物管理员,我想我应该能够使用它从命名空间中的豆荚此主机名。

对于卡夫卡1.0,我已经创建了自己的集装箱形象,我可以用环境变量控制......我设置zookeeper.connect到动物园管理员:2181。 我假设Kubernetes DNS将解决这一点,并打开该服务的连接。

不幸的是,我得到:

[2018-01-03 15:48:26,292] INFO Waiting for keeper state SyncConnected (org.I0Itec.zkclient.ZkClient)
[2018-01-03 15:48:32,293] INFO Terminate ZkClient event thread. (org.I0Itec.zkclient.ZkEventThread)
[2018-01-03 15:48:46,286] INFO Opening socket connection to server zookeeper.sandbox.svc.cluster.local/10.107.41.148:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2018-01-03 15:48:46,299] INFO Socket connection established to zookeeper.sandbox.svc.cluster.local/10.107.41.148:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2018-01-03 15:48:46,319] INFO Session establishment complete on server zookeeper.sandbox.svc.cluster.local/10.107.41.148:2181, sessionid = 0x10000603c560001, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)
[2018-01-03 15:48:46,331] INFO Session: 0x10000603c560001 closed (org.apache.zookeeper.ZooKeeper)
[2018-01-03 15:48:46,333] FATAL Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer)
org.I0Itec.zkclient.exception.ZkTimeoutException: Unable to connect to zookeeper server 'zookeeper:2181' with timeout of 6000 ms
    at org.I0Itec.zkclient.ZkClient.connect(ZkClient.java:1233)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:157)
    at org.I0Itec.zkclient.ZkClient.<init>(ZkClient.java:131)
    at kafka.utils.ZkUtils$.createZkClientAndConnection(ZkUtils.scala:115)
    at kafka.utils.ZkUtils$.withMetrics(ZkUtils.scala:92)
    at kafka.server.KafkaServer.initZk(KafkaServer.scala:346)
    at kafka.server.KafkaServer.startup(KafkaServer.scala:194)
    at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38)
    at kafka.Kafka$.main(Kafka.scala:92)
    at kafka.Kafka.main(Kafka.scala)

所以我假设我有一个通用的网络问题在我的群集,然后我发现我的东西更加混乱......如果我设置zookeeper.connect到10.107.41.148:2181(动物园管理员服务的当前地址),连接作品(从卡夫卡至少动物园管理员)。

[2018-01-03 15:51:31,092] INFO Waiting for keeper state SyncConnected (org.I0Itec.zkclient.ZkClient)
[2018-01-03 15:51:31,094] INFO Opening socket connection to server 10.107.41.148/10.107.41.148:2181. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)
[2018-01-03 15:51:31,105] INFO Socket connection established to 10.107.41.148/10.107.41.148:2181, initiating session (org.apache.zookeeper.ClientCnxn)
[2018-01-03 15:51:31,134] INFO Session establishment complete on server 10.107.41.148/10.107.41.148:2181, sessionid = 0x10000603c560005, negotiated timeout = 6000 (org.apache.zookeeper.ClientCnxn)

在此设置下,我能够使用饲养员服务从kubernetes群集的主机如“斌/ kafka-topics.sh --list --zookeeper 10.107.41.148:2181”做。 生产的消息不工作你......我认为,一旦网络正常工作,我需要添加卡夫卡标榜地址经过...

kafka-console-producer.sh --broker-list 10.100.117.196:9092 --topic test1
>test-msg1
>[2018-01-03 17:05:35,689] WARN [Producer clientId=console-producer] Connection to node 0 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

任何提示什么是错的我Kubernetes网络设置,或者至少从哪里开始解决问题

谢谢你,最好的问候,帕维尔

Answer 1:

如果你使用statefulsets,你需要首先部署服务。

我在这里的服务。

apiVersion: v1
kind: Service
metadata:
  name: zookeeper
  labels:
    app: zookeeper
spec:
  clusterIP: None
  ports:
  - port: 2181
    name: client
  - port: 2888
    name: server
  - port: 3888
    name: leader-election
  selector:
    app: zookeeper

在这里,configmap(以后使用):

 apiVersion: v1
    kind: ConfigMap
    metadata:
      name: zookeeper-cm
    data:
      jvm.heap: "1G"
      tick: "2000"
      init: "10"
      sync: "5"
      client.cnxns: "60"
      snap.retain: "3"
      purge.interval: "0"

在这里我statefulset:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: zookeeper
spec:
  serviceName: zookeeper
  replicas: 1
  template:
    metadata:
      labels:
        app: zookeeper
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                    - zookeeper
              topologyKey: "kubernetes.io/hostname"
      containers:
      - name: zookeeper
        imagePullPolicy: IfNotPresent
        image: sorintdev/zookeeper:20171204m
        resources:
          requests:
            memory: 500Mi
            cpu: 200m
        ports:
        - containerPort: 2181
          name: client
        - containerPort: 2888
          name: server
        - containerPort: 3888
          name: leader-election
        env:
        - name : ZK_REPLICAS
          value: "1"
        - name : ZK_HEAP_SIZE
          valueFrom:
            configMapKeyRef:
                name: zookeeper-cm
                key: jvm.heap
        - name : ZK_TICK_TIME
          valueFrom:
            configMapKeyRef:
                name: zookeeper-cm
                key: tick
        - name : ZK_INIT_LIMIT
          valueFrom:
            configMapKeyRef:
                name: zookeeper-cm
                key: init
        - name : ZK_SYNC_LIMIT
          valueFrom:
            configMapKeyRef:
                name: zookeeper-cm
                key: tick
        - name : ZK_MAX_CLIENT_CNXNS
          valueFrom:
            configMapKeyRef:
                name: zookeeper-cm
                key: client.cnxns
        - name: ZK_SNAP_RETAIN_COUNT
          valueFrom:
            configMapKeyRef:
                name: zookeeper-cm
                key: snap.retain
        - name: ZK_PURGE_INTERVAL
          valueFrom:
            configMapKeyRef:
                name: zookeeper-cm
                key: purge.interval
        - name: ZK_CLIENT_PORT
          value: "2181"
        - name: ZK_SERVER_PORT
          value: "2888"
        - name: ZK_ELECTION_PORT
          value: "3888"
        command:
        - bash
        - -c
        - zkGenConfig.sh && zkServer.sh start-foreground
        readinessProbe:
          exec:
            command:
            - "zkOk.sh"
          initialDelaySeconds: 10
          timeoutSeconds: 5
        livenessProbe:
          exec:
            command:
            - "zkOk.sh"
          initialDelaySeconds: 10
          timeoutSeconds: 5
        volumeMounts:
        - name: data
          mountPath: /var/lib/zookeeper
      securityContext:
        runAsUser: 1000
        fsGroup: 1000
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      resources:
        requests:
          storage: 1Gi
      accessModes:
      - ReadWriteOnce
      storageClassName: zookeeper-class

你部署了工作动物园管理员配置和他们选出的主之后,你可以用卡夫卡的部署进行。

一旦饲养员部署,您的卡夫卡配置必须引用通过服务的ZooKeeper statefulset。 在卡夫卡必须定义/覆盖此属性:

--override zookeeper.connect=zookeeper-0.zookeeper:2181

从吊舱内,你应该ping zookeeper-0.zookeeper成功地。

希望这可以帮助。



文章来源: Kubernetes service not working as expected with kafka