How to access Kafka through nodeport

3.1k views Asked by At

I want to access my Kafka cluster using nodeport.Here is my CRD using which I am trying to expose Kafka using nodeport.

apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
  name: my-cluster
spec:
  kafka:
    version: 2.6.0
    replicas: 3
    listeners:
      - name: plain
        port: 9092
        type: internal
        tls: false
      - name: tls
        port: 9093
        type: nodeport
        tls: false
    overrides:
      bootstrap:
        nodePort: 32100
      brokers:
      - broker: 0
        nodePort: 32000
      - broker: 1
        nodePort: 32001
      - broker: 2
        nodePort: 32002
    config:
      offsets.topic.replication.factor: 3
      transaction.state.log.replication.factor: 3
      transaction.state.log.min.isr: 2
      log.message.format.version: "2.6"
    storage:
      type: jbod
      volumes:
      - id: 0
        type: persistent-claim
        size: 100Gi
        deleteClaim: false
  zookeeper:
    replicas: 3
    storage:
      type: persistent-claim
      size: 100Gi
      deleteClaim: false
  entityOperator:
    topicOperator: {}
    userOperator: {}



ist@ist-1207:~$ kubectl get node ist-1207 -o=jsonpath='{range .status.addresses[*]}{.type}{"\t"}{.address}{"\n"}'

InternalIP  192.168.105.62

Hostname    ist-1207



ist@ist-1207:~$ kubectl exec my-cluster-kafka-0 -c kafka -it -n strimzi -- cat /tmp/strimzi.properties | grep advertised

advertised.listeners=REPLICATION-9091://my-cluster-kafka-0.my-cluster-kafka-brokers.strimzi.svc:9091,PLAIN-9092://my-cluster-kafka-0.my-cluster-kafka-brokers.strimzi.svc:9092,TLS-9093://192.168.105.62:31255

I matched both the address where my Kafka pods are running and the address advertised by the Kafka broker ..both are same but still I am not able to access . Here is the services:

   NAMESPACE     NAME                             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
default       kubernetes                       ClusterIP   10.96.0.1        <none>        443/TCP                      2d17h
kube-system   kube-dns                         ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP       2d17h
strimzi       my-cluster-kafka-bootstrap       ClusterIP   10.97.105.228    <none>        9091/TCP,9092/TCP            2d15h
strimzi       my-cluster-kafka-brokers         ClusterIP   None             <none>        9091/TCP,9092/TCP            2d15h
strimzi       my-cluster-kafka-tls-0           NodePort    10.100.213.101   <none>        9093:31255/TCP               2d15h
strimzi       my-cluster-kafka-tls-1           NodePort    10.99.126.141    <none>        9093:30493/TCP               2d15h
strimzi       my-cluster-kafka-tls-2           NodePort    10.108.221.176   <none>        9093:30437/TCP               2d15h
strimzi       my-cluster-kafka-tls-bootstrap   NodePort    10.100.212.113   <none>        9093:31091/TCP               2d15h
strimzi       my-cluster-zookeeper-client      ClusterIP   10.109.94.99     <none>        2181/TCP                     2d15h
strimzi       my-cluster-zookeeper-nodes       ClusterIP   None             <none>        2181/TCP,2888/TCP,3888/TCP   2d15h
strimzi       my-connect-cluster-connect-api   ClusterIP   10.101.91.208    <none>        8083/TCP                     2d16h

[kafka@my-cluster-kafka-0 kafka]$ bin/kafka-topics.sh --bootstrap-server 192.168.105.62:31255 --list

Error while executing topic command : org.apache.kafka.common.errors.TimeoutException: Call(callName=listTopics, deadlineMs=1606116174727, tries=1, nextAllowedTryMs=1606116174828) timed out at 1606116174728 after 1 attempt(s)

[2020-11-23 07:22:54,743] ERROR java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Call(callName=listTopics, deadlineMs=1606116174727, tries=1, nextAllowedTryMs=1606116174828) timed out at 1606116174728 after 1 attempt(s)

    at org.apache.kafka.common.internals.KafkaFutureImpl.wrapAndThrow(KafkaFutureImpl.java:45)

    at org.apache.kafka.common.internals.KafkaFutureImpl.access$000(KafkaFutureImpl.java:32)

    at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:89)

    at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:260)

    at kafka.admin.TopicCommand$AdminClientTopicService.getTopics(TopicCommand.scala:352)

    at kafka.admin.TopicCommand$AdminClientTopicService.listTopics(TopicCommand.scala:260)

    at kafka.admin.TopicCommand$.main(TopicCommand.scala:66)

    at kafka.admin.TopicCommand.main(TopicCommand.scala)

Caused by: org.apache.kafka.common.errors.TimeoutException: Call(callName=listTopics, deadlineMs=1606116174727, tries=1, nextAllowedTryMs=1606116174828) timed out at 1606116174728 after 1 attempt(s)

Caused by: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.

 (kafka.admin.TopicCommand$)  

I stuck here .I am not able to access . please help me if I am doing something wrong.

1

There are 1 answers

3
ppatierno On BEST ANSWER

I think the problem is that you configured TLS enabled on the nodeport listener but don't think you have extracted the cluster CA cert and configured the truststore on the kafka-topics client as described in the official documentation. If you don't need TLS, just disable it with tls: false on the nodeport listener. You can also read more about using nodeport on this blog post:

https://strimzi.io/blog/2019/04/23/accessing-kafka-part-2/

Don't be worried that it's using the older way to define listeners; your current one is right.