Kafka Administration Commands

Kafka Administration Commands

Introduction

Apache Kafka is a distributed event-streaming platform used to build real-time data pipelines and streaming applications. In a production environment,

1. List Topics

Displays all topics available in the Kafka cluster.

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

2. Create Topic

kafka-topics.sh –bootstrap-server localhost:9092 –create –topic orders –partitions 3 –replication-factor 3

3. Describe Topic

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

4. Delete Topic

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

5. Increase Partitions

kafka-topics.sh –bootstrap-server localhost:9092 –alter –orders –partitions 8

6. View Topic Configuration

kafka-configs.sh –bootstrap-server localhost:9092 –entity-type topics –entity-name orders –describe

7. Modify Topic Configuration

kafka-configs.sh –bootstrap-server localhost:9092 –entity-type topics –entity-name orders –alter –add-config retention.ms=86400000

8. List Consumer Groups

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

9. Describe Consumer Group

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

10. Reset Consumer Offsets

kafka-consumer-groups.sh –bootstrap-server localhost:9092 –group order-service –topic orders –reset-offsets –to-earliest –execute

11. View Broker API Versions

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

12. Display Cluster ID

kafka-cluster.sh –bootstrap-server localhost:9092 cluster-id

13. View Metadata Quorum (KRaft)

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

14. Monitor Broker Disk Usage

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

15. Reassign Partitions

Generate reassignment:

kafka-reassign-partitions.sh –bootstrap-server localhost:9092 –generate

Execute reassignment:

kafka-reassign-partitions.sh –bootstrap-server localhost:9092 –execute

Verify reassignment:

kafka-reassign-partitions.sh –bootstrap-server localhost:9092 –verify

16. Delete Records

kafka-delete-records.sh –bootstrap-server localhost:9092 –offset-json-file delete-offset.json

Recent Posts