I have deployed strimzi kafka on kubernetes and I have kube setup in my local as well. But each time I want a new topic in kafka, I need to create one by importing the yaml file via rancher and provide the topic name.
Is there a way to create a kafka topic directly via kubectl command?
These are the commands I use to run kafka:
Producer: kubectl run kafka-producer1 -ti --image=strimzi/kafka:0.18.0-kafka-2.4.0 --rm=true --restart=Never -- bin/kafka-console-producer.sh --broker-list 11.23.41.32:31025 --topic topic-name
Consumer: kubectl run kafka-consumer1 -ti --image=strimzi/kafka:0.18.0-kafka-2.4.0 --restart=Never -- bin/kafka-console-consumer.sh --bootstrap-server 11.23.41.32:31025 --topic topic-name --from-beginning
Steps to create topic via commandline : (assumed zookeeper running on port 2181 and kafka server on 9092)
kubectl exec -it kafka-pod-name -- /bin/bash
kafka-topics --bootstrap-server localhost:9092 --create --topic topic-name --replication-factor 1 --partitions 3
a) produce-->
kafka-console-producer --broker-list localhost:9092 --topic <topic-you-created-before>
b) consume--> kafka-console-consumer --bootstrap-server localhost:9092 --topic audit --from-beginning
you can see the message(provided by producer) here