Kafka Migration
Migration guides for Apache Kafka clusters.
Migration Types
Section titled “Migration Types”| Migration | Complexity | Downtime |
|---|---|---|
| Version upgrade | Low-Medium | Zero (rolling) |
| ZooKeeper to KRaft | Medium | Zero (rolling) |
| Cluster migration | High | Depends on approach |
| Cloud migration | High | Depends on approach |
ZooKeeper to KRaft Migration
Section titled “ZooKeeper to KRaft Migration”Overview
Section titled “Overview”Migration Steps
Section titled “Migration Steps”1. Prepare cluster
# Verify all brokers are healthykafka-broker-api-versions.sh --bootstrap-server kafka:9092
# Check for under-replicated partitionskafka-topics.sh --bootstrap-server kafka:9092 \ --describe --under-replicated-partitions2. Deploy KRaft controllers
process.roles=controllernode.id=100controller.quorum.voters=100@ctrl1:9093,101@ctrl2:9093,102@ctrl3:9093listeners=CONTROLLER://0.0.0.0:9093controller.listener.names=CONTROLLER3. Enable migration mode on controllers
# Add to controller.propertieszookeeper.connect=zk1:2181,zk2:2181,zk3:2181zookeeper.metadata.migration.enable=true4. Start migration
# Format controller storagekafka-storage.sh format -t $(kafka-storage.sh random-uuid) \ -c controller.properties
# Start controllerskafka-server-start.sh controller.properties5. Roll brokers to enable migration
# Add to server.propertiescontroller.quorum.voters=100@ctrl1:9093,101@ctrl2:9093,102@ctrl3:9093controller.listener.names=CONTROLLER6. Complete migration
# Verify migration statuskafka-metadata.sh --snapshot /var/kafka/__cluster_metadata-0/*.log \ --command "migration-state"
# Disable ZooKeeper on controllers# Remove: zookeeper.metadata.migration.enable=true# Restart controllers7. Remove ZooKeeper dependency from brokers
# Remove from server.properties# zookeeper.connect=...
# Rolling restart brokersVersion Upgrades
Section titled “Version Upgrades”Rolling Upgrade Process
Section titled “Rolling Upgrade Process”Pre-Upgrade Checklist
Section titled “Pre-Upgrade Checklist”- Review release notes for breaking changes
- Verify client compatibility
- Backup configurations
- Test upgrade in non-production
- Plan rollback procedure
Upgrade Commands
Section titled “Upgrade Commands”# Set protocol version before upgrade# server.propertiesinter.broker.protocol.version=3.6log.message.format.version=3.6
# Upgrade each brokerfor broker in broker1 broker2 broker3; do # Stop ssh $broker "sudo systemctl stop kafka"
# Install new version ssh $broker "sudo yum install kafka-3.7"
# Start ssh $broker "sudo systemctl start kafka"
# Wait for recovery sleep 60 kafka-topics.sh --bootstrap-server kafka:9092 \ --describe --under-replicated-partitionsdone
# Update protocol version# server.propertiesinter.broker.protocol.version=3.7log.message.format.version=3.7
# Rolling restartCluster Migration
Section titled “Cluster Migration”Using MirrorMaker 2
Section titled “Using MirrorMaker 2”Migration Steps
Section titled “Migration Steps”1. Set up target cluster
# Create topics on target with same configurationkafka-topics.sh --bootstrap-server target:9092 \ --create --topic my-topic \ --partitions 12 --replication-factor 32. Deploy MirrorMaker 2
clusters=source,targetsource.bootstrap.servers=source-kafka:9092target.bootstrap.servers=target-kafka:9092
source->target.enabled=truesource->target.topics=.*
sync.group.offsets.enabled=trueemit.checkpoints.enabled=true3. Verify replication
# Check lagkafka-consumer-groups.sh --bootstrap-server target:9092 \ --describe --group mm2-source-target
# Verify data integritykafka-console-consumer.sh --bootstrap-server target:9092 \ --topic my-topic --from-beginning --max-messages 104. Migrate consumers
# Translate offsets# Consumers can read checkpoints topic to find equivalent offset5. Migrate producers
# Update bootstrap.servers to target cluster# Deploy updated configuration6. Decommission source
# Stop MirrorMaker# Verify no traffic to source# Decommission source clusterRollback Procedures
Section titled “Rollback Procedures”Version Rollback
Section titled “Version Rollback”# Stop brokersudo systemctl stop kafka
# Install previous versionsudo yum downgrade kafka-3.6
# Ensure protocol version matches# server.propertiesinter.broker.protocol.version=3.6
# Start brokersudo systemctl start kafkaMigration Rollback
Section titled “Migration Rollback”# For ZK to KRaft migration:# 1. Re-enable ZooKeeper on brokers# 2. Rolling restart brokers# 3. Shut down KRaft controllers# 4. Verify cluster operates with ZooKeeperRelated Documentation
Section titled “Related Documentation”→ Version Compatibility - JDK, client-broker, and KRaft compatibility matrices
- Operations - Operational procedures
- Cluster Management - Cluster operations
- Architecture - System architecture
- Backup and Restore - DR procedures