<p>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.</p>
<p>Is there a way to create a kafka topic directly via kubectl command?</p>
<p>These are the commands I use to run kafka:</p>
<p><code>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</code></p>
<p><code>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</code></p>

veeresh
<p>Steps to create topic via commandline : (assumed zookeeper running on port 2181 and kafka server on 9092)</p>
<ol>
<li>Get inside the kafka pod by using this command</li>
</ol>
<p><code>kubectl exec -it kafka-pod-name -- /bin/bash</code></p>
<ol start="2">
<li>Create the topic by using below command</li>
</ol>
<p><code>kafka-topics --bootstrap-server localhost:9092 --create --topic topic-name --replication-factor 1 --partitions 3</code></p>
<ol start="3">
<li>you can verify the message produce and consume using below commands-</li>
</ol>
<p>a) produce--&gt;</p>
<ol>
<li><code>kafka-console-producer --broker-list localhost:9092 --topic &lt;topic-you-created-before&gt;</code></li>
<li>provide some message</li>
</ol>
<p>b) consume--&gt; <code>kafka-console-consumer --bootstrap-server localhost:9092 --topic audit --from-beginning</code></p>
<p>you can see the message(provided by producer) here</p>
