Apache Kafka is a widely used distributed streaming platform known for its fault tolerance, scalability, and performance. Amazon Managed Streaming for Apache Kafka (MSK) simplifies the setup, management, and monitoring of Kafka clusters in the AWS environment. In this guide, we’ll walk through the process of rebalancing a Kafka cluster hosted on AWS MSK using CLI commands.
Prerequisites
- Access to an AWS account with permissions to manage MSK clusters.
- Installed Kafka CLI tools.
- Basic understanding of Kafka architecture and concepts.
Steps to Rebalance a Kafka Cluster
Step 1: Navigate to Kafka Bin Directory
cd /path/to/kafka/bin
Step 2: Set Broker URL as a Variable
export bs={Replace_this_with_broker_url}
Step 3: Ensure that you have the necessary permissions to view the topic’s configuration and current statistics. Below is the output displaying this information.
./kafka-topics.sh --bootstrap-server $bs --describe --topic test-topic Topic: test-topic Partition: 0 Leader: 6 Replicas: 6,4,5 Isr: 6,5,4 Topic: test-topic Partition: 1 Leader: 6 Replicas: 6,5,4 Isr: 6,5,4 Topic: test-topic Partition: 2 Leader: 6 Replicas: 6,4,5 Isr: 6,5,4 Topic: test-topic Partition: 3 Leader: 6 Replicas: 6,5,4 Isr: 6,5,4 Topic: test-topic Partition: 4 Leader: 6 Replicas: 6,5,4 Isr: 6,5,4 Topic: test-topic Partition: 5 Leader: 6 Replicas: 6,4,5 Isr: 6,5,4
If access errors occur (common in AWS MSK), set credentials:
export AWS_ACCESS_KEY_ID="replace_access_key" export AWS_SECRET_ACCESS_KEY="replace_secret_key" export AWS_SESSION_TOKEN="replace_session_token"