0

Kafka broker runs beautifully when running locally via docker-compose.

version: "3"
services:
  zookeeper:
    image: 'bitnami/zookeeper:latest'
    ports:
      - '2181:2181'
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
  kafka:
    image: 'bitnami/kafka:latest'
    ports:
      - '9092:9092'
    environment:
      - KAFKA_BROKER_ID=1
      - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
      - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092
      - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
      - ALLOW_PLAINTEXT_LISTENER=yes
    depends_on:
      - zookeeper

When running via kubernetes though

apiVersion: v1
kind: Service
metadata:
  name: zevrant-kafka-zookeeper-service
spec:
  ports:
    - port: 443
      targetPort: 2181
  selector:
    app: zevrant-kafka-zookeeper-service
---
apiVersion: v1
kind: Service
metadata:
  name: zevrant-kafka-service
spec:
  type: NodePort
  ports:Connection to node -1 (/<IP_ADDRESS>:30129) could not be established. Broker may not be available.
    - port: 443
      targetPort: 9092
      nodePort: 30129
  selector:
    app: zevrant-kafka-service
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: zevrant-kafka-zookeeper-service-deployment
  labels:
    app: zevrant-kafka-zookeeper-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zevrant-kafka-zookeeper-service
  template:
    metadata:
      labels:
        app: zevrant-kafka-zookeeper-service
    spec:
      volumes:
        - name: zookeeper-data
          nfs:
            server: <IP_ADDRESS>
            path: /zookeeper
      imagePullSecrets:
        - name: regcred
      nodeSelector:
        architecture: amd64
      containers:
        - name: zevrant-kafka-zookeeper-service
          image: bitnami/zookeeper:3.7.0
          env:
            - name: ALLOW_ANONYMOUS_LOGIN
              value: "yes"
          ports:
            - containerPort: 2181
          volumeMounts:
            - name: zookeeper-data
              mountPath: /bitnami/zookeeper
        - name: zevrant-kafka-zookeper-ui-service
          image: elkozmon/zoonavigator:1.1.0
          ports:
            - containerPort: 9000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: zevrant-kafka-service-daemonset
  labels:
    app: zevrant-kafka-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zevrant-kafka-service
  template:
    metadata:
      labels:
        app: zevrant-kafka-service
    spec:
      volumes:
        - name: kafka-storage
          hostPath:
            path: /opt/kafka/dev/
      imagePullSecrets:
        - name: regcred
      nodeSelector:
        architecture: amd64
      containers:
        - name: zevrant-kafka-broker-service
          image: bitnami/kafka:2.8.0
          volumeMounts:
            - name: kafka-storage
              mountPath: /bitnami/kafka
          ports:
            - containerPort: 9092
          env:
            - name: ALLOW_PLAINTEXT_LISTENER
              value: "yes"
            - name: KAFKA_CFG_ZOOKEEPER_CONNECT
              value: "zevrant-kafka-zookeeper-service:443"
            - name: KAFKA_BROKER_ID
              value: "1"
            - name: KAFKA_CFG_LISTENERS
              value: "PLAINTEXT://0.0.0.0:9092"
            - name: KAFKA_CFG_ADVERTISED_LISTENERS
              value: "PLAINTEXT://<IP_ADDRESS>:30129"

The broker starts but repeatedly spams the error

INFO [Admin Manager on Broker 1]: Error processing create topic request CreatableTopic(name='zevrant-video-stream', numPartitions=1, replicationFactor=1, assignments=[], configs=[]) (kafka.server.ZkAdminManager)

I used the same command on both clusters to create the topic aside from the connection details and in both cases I ran the command from inside the running broker container.

Locally

kafka-topics.sh --create --topic zevrant-video-stream --zookeeper localhost:2181 --partitions 1 --replication-factor 1 --config retention.ms=86400000

Kubernetes

kafka-topics.sh --create --topic zevrant-video-stream --zookeeper zevrant-kafka-zookeeper-service:443 --partitions 1 --replication-factor 1 --config retention.ms=86400000

I'm not really sure why this works in one place and not the other.

Attempting to connect a producer to the kubernetes broker i receive

Connection to node -1 (/<IP_ADDRESS>:30129) could not be established. Broker may not be available.

When querying zookeeper for broker information, zookeeper shows the broker as connected

zkCli.sh get /brokers/ids/1


{"listener_security_protocol_map":{"PLAINTEXT":"PLAINTEXT"},"endpoints":["PLAINTEXT://<IP_ADDRESS>:9092"],"jmx_port":-1,"features":{},"host":"<IP_ADDRESS>","timestamp":"1622398259745","port":9092,"version":5}

What would cause the broker to connected, online, but unavailable?

Zevrant
  • 11
  • 2
  • Hello @Zevrant, welcome to Serverfault. Could you tell me how did you set up your Kubernetes cluster? Did you also see this similar topic: https://stackoverflow.com/questions/47677549? – Mikołaj Głodziak May 31 '21 at 08:31
  • I did and running the broker with listening on localhost causes the broker to not respond to external requests routed through kubernetes, and unlike in the post you mentioned and if you read above, the broker is registered in zookeeper. – Zevrant May 31 '21 at 12:19
  • Can you be more specific with you question of 'how i set up my kubernetes cluster?' It's a bare metal install running on multiple nodes. I have at least 12 other different applications running in this namespace and have verified that it's not a network issue as communication from zookeeper to the broker is fine and communication from the producer is able to connect but gets the unavailable message which is different that the unable to establish connection error. – Zevrant May 31 '21 at 12:19
  • I wanted to know if you deployed k8s as bare metal or, for example, using the cloud. Thanks for the clarification. You need to know why broker may be not available. You need to check what is happening with this node. Did you check logs for this node (with broker)? What output do you have when you get `kubectl get nodes`? – Mikołaj Głodziak May 31 '21 at 14:17
  • So this is more of a Kafka question than kubernetes. All of my nodes are online and functioning normally. As posted above I have verified that both zookeeper and the producer can connect to the broker, the broker is responding to the producer that it is unavailable. – Zevrant Jun 01 '21 at 15:20

1 Answers1

1

turns out there is additional configuration needed for running inside a closed network as discussed here

Zevrant
  • 11
  • 2