Unable to use kafka broker from a Kubernetes pod

15 Views Asked by At

I have currently deployed a kafka broker in a kubernetes cluster which is listening to another service in the same namespace . I have to now test the service from my local . I need to send Json files to the server which decodes it while consuming the message . I have tested the service multiple times locally using a python script. But now I want to test it while its in the cluster.

I went with a simple port forward kubectl port-forward kafka-0 9092:9092 -n testnamspace the ports are getting forwarded successfully [![enter image description here :

enter image description here

but when I try to run my python script I am not getting any expected response the cli is blank. But I am able to connect to the kafka broker I am not getting any No broker available message.

This is the test script I am running

import json
from kafka import KafkaConsumer

consumer = KafkaConsumer(bootstrap_servers='127.0.0.1:9092',
                         auto_offset_reset='latest',
                         enable_auto_commit=True,
                         )
consumer.subscribe('model_predict')


for message in consumer:
    print(message.value)
    result = json.loads((message.value).decode('utf-8'))
    print(result)
0

There are 0 best solutions below