# Create Kafka Topic (from CLI)

In 
Published 2022-12-03

This tutorial explains to you how to create a Kafka topic from CLI on Linux. This tutorial has an example as well.

In order to create a Kafka Topic you have to run the following command:

kafka-topics.sh --create \
--topic my-topic1 \
--replication-factor 2 \
--partitions 2 \
--zookeeper localhost:2181/kafka

Attention:

  1. kafka-topics.sh must be defined in PATH environment variable

  2. This topic has the name my-topic1

  3. This topic has 2 partitions (Partition 0 and Partition 1)

  4. We have 2 replicas for each partition like in the image below

  5. At any time only one Broker can be a leader for a given Partition

  6. Only that leader can receive and serve data for a Partition and the other Brokers will synchronize the data

  7. Therefore, each Partition has one leader and multiple ISR (In-Sync-Replica)

When you connect to zookeeper to send a request, you could use any zookeeper server from the cluster:

If you want to see the topics list you can run the kafka-topics.sh --list --zookeeper localhost:2181/kafka command: