Operations 6 min read

Comprehensive Guide to Kafka Commands (2026 Edition)

This article provides a step‑by‑step reference for Kafka command‑line tools, covering version checks, topic creation, listing, describing, deletion, partition alteration, consumer‑group inspection, offset resets, producer/consumer testing, broker API version queries, cluster metadata, leader election, and log‑directory monitoring, with concrete examples and expected outputs.

Architect Chen
Architect Chen
Architect Chen
Comprehensive Guide to Kafka Commands (2026 Edition)

1. Check Kafka version

kafka-topics.sh --version

Output example:

3.8.0

2. Create a topic

kafka-topics.sh \
  --create \
  --topic order \
  --bootstrap-server localhost:9092 \
  --partitions 3 \
  --replication-factor 2

Result:

Created topic order-topic.

3. List all topics

kafka-topics.sh --list --bootstrap-server localhost:9092

Result: a list of topic names such as user-topic, order-topic, pay-topic.

4. Describe a topic

kafka-topics.sh --describe --topic order --bootstrap-server localhost:9092

Result shows partition count, leader, ISR, and replica distribution, e.g. PartitionCount: 3, ReplicationFactor: 2.

5. Delete a topic

kafka-topics.sh --delete --topic order --bootstrap-server localhost:9092

Result:

Topic order-topic marked for deletion.

6. Increase topic partitions

kafka-topics.sh --alter --topic order \
  --partitions 6 \
  --bootstrap-server localhost:9092

Note: Kafka only allows increasing partitions; decreasing is not permitted.

7. List consumer groups

kafka-consumer-groups.sh --list --bootstrap-server localhost:9092

Result: a list of consumer‑group IDs such as order-group, user-group.

8. Describe a consumer group

kafka-consumer-groups.sh --describe --group order-group \
  --bootstrap-server localhost:9092

Result includes lag, offset, and partition assignment for each member.

9. Reset consumer offsets to earliest

kafka-consumer-groups.sh --reset-offsets \
  --group order-group \
  --to-earliest \
  --execute --all-topics \
  --bootstrap-server localhost:9092

Typical use cases: data replay, test‑environment recovery.

10. Start a console producer

kafka-console-producer.sh --topic order --bootstrap-server localhost:9092

Input messages (e.g., order001, order002, order003) are sent to the specified topic.

11. Start a console consumer

kafka-console-consumer.sh --topic order \
  --from-beginning \
  --bootstrap-server localhost:9092

Outputs the messages previously produced.

12. Query broker API versions

kafka-broker-api-versions.sh --bootstrap-server localhost:9092

Shows supported protocol versions, e.g. Produce API 0‑9, Fetch API 1‑13, useful for client‑compatibility checks.

13. Get topic offset information

kafka-run-class.sh kafka.tools.GetOffsetShell \
  --broker-list localhost:9092 \
  --topic order

Result example: order-0:10000 (partition 0 current offset).

14. View cluster metadata

kafka-metadata-quorum.sh --bootstrap-server localhost:9092 --describe --status

In KRaft mode the output includes ClusterId, LeaderId, and overall cluster health.

15. Trigger preferred leader election

kafka-leader-election.sh --bootstrap-server localhost:9092 \
  --election-type preferred \
  --all-topics --partitions

Applicable after broker recovery or for load‑balancing leader distribution.

16. Inspect log‑directory usage

kafka-log-dirs.sh --bootstrap-server localhost:9092 --describe

Returns JSON with broker ID and each log directory path, aiding disk‑capacity planning and hotspot detection.

The article also provides a concise table summarising command categories (Topic management, Consumer‑group management, Message testing, Cluster management, Operational monitoring, Offset management) and their core commands.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Kafkacommand-lineconsumer groupstopic managementbroker monitoring
Architect Chen
Written by

Architect Chen

Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.