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.
1. Check Kafka version
kafka-topics.sh --versionOutput example:
3.8.02. Create a topic
kafka-topics.sh \
--create \
--topic order \
--bootstrap-server localhost:9092 \
--partitions 3 \
--replication-factor 2Result:
Created topic order-topic.3. List all topics
kafka-topics.sh --list --bootstrap-server localhost:9092Result: 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:9092Result 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:9092Result:
Topic order-topic marked for deletion.6. Increase topic partitions
kafka-topics.sh --alter --topic order \
--partitions 6 \
--bootstrap-server localhost:9092Note: Kafka only allows increasing partitions; decreasing is not permitted.
7. List consumer groups
kafka-consumer-groups.sh --list --bootstrap-server localhost:9092Result: 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:9092Result 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:9092Typical use cases: data replay, test‑environment recovery.
10. Start a console producer
kafka-console-producer.sh --topic order --bootstrap-server localhost:9092Input 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:9092Outputs the messages previously produced.
12. Query broker API versions
kafka-broker-api-versions.sh --bootstrap-server localhost:9092Shows 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 orderResult example: order-0:10000 (partition 0 current offset).
14. View cluster metadata
kafka-metadata-quorum.sh --bootstrap-server localhost:9092 --describe --statusIn 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 --partitionsApplicable after broker recovery or for load‑balancing leader distribution.
16. Inspect log‑directory usage
kafka-log-dirs.sh --bootstrap-server localhost:9092 --describeReturns 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect Chen
Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
