Configure KRaft Dynamic Controller Quorum using Ansible Playbooks
A KRaft dynamic controller quorum lets you add and remove controllers in a running cluster without rebuilding it. Ansible Playbooks for Confluent Platform (Confluent Ansible) supports dynamic quorum as an opt-in feature for Confluent Platform 8.4 and later.
This topic describes how to:
Deploy a new Confluent Platform cluster with a dynamic quorum
Migrate an existing static quorum to a dynamic quorum
Add controllers to, and remove controllers from, a dynamic quorum
Recover a dynamic quorum after you lose controllers
Static quorum and dynamic quorum
The following table compares the two quorum types.
Characteristic |
Static quorum |
Dynamic quorum |
|---|---|---|
Controller configuration |
|
|
|
|
|
Add or remove controllers |
Not supported without rebuilding the cluster |
Supported at runtime |
Requirements and considerations
Confluent Platform 8.4.0 or later.
Dedicated controllers in the
kafka_controllerinventory group.Confluent Ansible supports dynamic quorum for a single cluster. Multi-region deployments are not covered in this topic.
Every controller is reachable from the Ansible host during every playbook run.
Dynamic quorum is opt-in. Set
kraft_dynamic_quorum_enabled: truein the inventory file to enable it.
In the commands that follow, <controller_port> is the value of
kafka_controller_port in your inventory file. The default is 9093.
Choose the number of controllers
The quorum can elect a leader and accept metadata changes only while a majority
of voters is available. For N voters, the majority is floor(N / 2) + 1.
Voters |
Majority |
Failures tolerated |
|---|---|---|
3 |
2 |
1 |
4 |
3 |
1 |
5 |
3 |
2 |
6 |
4 |
2 |
Variables
Variable |
Default |
Description |
|---|---|---|
|
|
Set to |
|
|
Required for a new deployment. The one controller that creates the new
quorum. The value must be a |
Confluent Ansible builds controller.quorum.bootstrap.servers from the
kafka_controller group, and follows hostname_aliasing_enabled the same
way the controller listeners do. It also sets
controller.quorum.auto.join.enable=true for you. Confluent Ansible does not
set controller.quorum.voters, because only a static quorum uses that
property.
Deploy a new cluster with a dynamic quorum
To deploy a new cluster with a dynamic quorum from the start:
Prepare the inventory file, for example a cluster with three controllers and three brokers. Set the following variables under
all.vars:all: vars: kraft_dynamic_quorum_enabled: true kafka_controller_initial_voter: kcontroller-1.example.com kafka_controller: hosts: kcontroller-1.example.com: kcontroller-2.example.com: kcontroller-3.example.com: kafka_broker: hosts: kbroker-1.example.com: kbroker-2.example.com: kbroker-3.example.com:
Run the playbook:
ansible-playbook -i hosts.yml confluent.platform.all
Confluent Ansible forms the quorum as follows:
Checks that Confluent Platform is 8.4.0 or later and KRaft is enabled. It then checks the data directory of every controller. A new quorum is created only if no controller is formatted yet. If Confluent Ansible cannot reach a controller, the run ends at this step without an error message. Make sure that every controller is reachable before you run the playbook.
Formats the initial voter with
--standalone. It becomes the only voter of the new quorum.Formats every other controller with
--no-initial-controllersand the same cluster ID. They start as observers.Promotes each observer to a voter through auto-join after it catches up with the leader.
Deploys the brokers with
controller.quorum.bootstrap.servers.
You can run the playbook again later. Confluent Ansible never formats a controller that is already formatted. A wiped controller rejoins the existing quorum as an observer and never creates a second quorum, even if it is the initial voter.
Verify the quorum
Run the following commands on any controller:
# Every controller is a voter (Leader or Follower), with low Lag.
kafka-metadata-quorum --bootstrap-controller <controller-host>:<controller_port> \
--command-config /etc/controller/client.properties describe --replication
# The quorum has a leader, and CurrentVoters lists every controller.
kafka-metadata-quorum --bootstrap-controller <controller-host>:<controller_port> \
--command-config /etc/controller/client.properties describe --status
# kraft.version is 1.
kafka-features --bootstrap-controller <controller-host>:<controller_port> \
--command-config /etc/controller/client.properties describe | grep kraft.version
In the describe --replication output, brokers always show as Observer.
Controllers show as Leader or Follower.
Troubleshoot a new deployment
requires every kafka_controller to set the same kafka_controller_initial_voterkafka_controller_initial_voteris empty, does not match akafka_controllerinventory hostname, or is set differently on some hosts. Set it once underall.varsto an inventory hostname.- The run ends early with no error message
A controller was unreachable from the Ansible host when Confluent Ansible checked the data directories. The run ends with
failed=0and no further tasks run. Check that the Ansible host can reach every host in thekafka_controllergroup, bring any unreachable controller online, and run the playbook again.- A controller stays an observer
Check that the controller caught up with the leader (low
Lagin thedescribe --replicationoutput) and thatcontroller.quorum.auto.join.enable=trueis in itsserver.propertiesfile. If you disabled auto-join, run the following command on that controller to promote it:kafka-metadata-quorum --bootstrap-controller <leader-host>:<controller_port> \ --command-config /etc/controller/server.properties add-controller
Detected a running static KRaft clusterThe cluster already runs a static quorum. Use the migration procedure in the next section.
Migrate a static quorum to a dynamic quorum
You can migrate an existing static KRaft quorum (kraft.version=0) to a
dynamic quorum (kraft.version=1) in place, without rebuilding the cluster.
The migration is a one-time, one-way operation. The playbook rolls the
controllers and brokers one at a time, so the cluster keeps serving during the
migration.
Requirements
Confluent Platform 8.4.0 or later, deployed by Confluent Ansible, running a static KRaft quorum.
A healthy controller quorum. The quorum has a leader and every controller is a voter.
The inventory file that you used to deploy the cluster.
Why a migration playbook is needed
You cannot set kraft_dynamic_quorum_enabled: true and run the normal
playbooks. controller.quorum.bootstrap.servers works only after
kraft.version is 1, so the feature must be upgraded first while the
controllers still use controller.quorum.voters.
If you run the normal playbooks with kraft_dynamic_quorum_enabled: true on a
running static cluster, they stop with an error that tells you to run
StaticToDynamicQuorumMigration.
Migration stages
The migration changes the configuration in the following order. Controllers
switch to controller.quorum.bootstrap.servers before brokers do.
Stage |
Controller configuration |
Broker configuration |
|
|---|---|---|---|
Start |
|
|
|
After upgrading |
|
|
|
After switching controllers |
|
|
|
After switching brokers |
|
|
|
The playbook runs the following stages. Each stage has its own tag.
Stage |
Tag |
Action |
|---|---|---|
Precheck |
|
Checks that |
Upgrade |
|
Runs |
Switch controller configuration |
|
Removes |
Restart controllers |
|
Restarts the controllers one at a time, with a health check after each. |
Switch broker configuration |
|
Removes |
Restart brokers |
|
Restarts the brokers one at a time, with a health check after each. |
Run the migration
Before you run the migration, note that it is a one-way operation.
Warning
The kraft.version upgrade cannot be undone. Kafka does not support
downgrading kraft.version from 1 to 0. Run the migration on a
staging cluster first.
To migrate:
Check the starting state on any controller.
kraft.versionmust be0, and every controller must be a voter:kafka-features --bootstrap-controller <controller-host>:<controller_port> \ --command-config /etc/controller/client.properties describe | grep kraft.version kafka-metadata-quorum --bootstrap-controller <controller-host>:<controller_port> \ --command-config /etc/controller/client.properties describe --replication
Add
kraft_dynamic_quorum_enabled: trueto the inventory file underall.vars. You don’t needkafka_controller_initial_voterbecause it is only used when a new cluster is created.Run the migration playbook before any other playbook that would render the new configuration:
ansible-playbook -i hosts.yml confluent.platform.StaticToDynamicQuorumMigration
Verify the migration:
# kraft.version is 1. kafka-features --bootstrap-controller <controller-host>:<controller_port> \ --command-config /etc/controller/client.properties describe | grep kraft.version # Controllers and brokers use bootstrap.servers and no longer use voters. # Run this command on each controller. grep -E '^controller\.quorum\.(voters|bootstrap\.servers)' /etc/controller/server.properties # Run this command on each broker. grep -E '^controller\.quorum\.(voters|bootstrap\.servers)' /etc/kafka/server.properties
After the migration, keep kraft_dynamic_quorum_enabled: true in the
inventory file. The normal playbooks now render the dynamic quorum
configuration.
If the migration stops partway
Fix the cause and run the same command again. Every stage is safe to repeat:
If
kraft.versionis already1, the upgrade is skipped.Configuration lines that are already switched are left as they are.
The restart stages restart the controllers and brokers again, one at a time. This causes another rolling restart but no downtime.
If the run stopped after the kraft.version upgrade, run it again soon. In
that state, kraft.version is 1 but the controllers and brokers still use
controller.quorum.voters. Don’t leave the cluster in this state for long,
because disaster recovery is harder in this state.
You can also run only the remaining stages with --tags. For example,
--tags static_to_dynamic_quorum_broker_config,static_to_dynamic_quorum_broker_restart.
Add controllers
With a dynamic quorum, adding a controller is a normal playbook run. You add the
host to the inventory and run the controller playbook. Confluent Ansible formats
the new controller to join the existing cluster, and auto-join makes it a voter.
You don’t need to run any kafka-metadata-quorum commands.
Before you begin, make sure that:
The cluster runs a dynamic quorum, deployed as a new cluster or migrated.
The quorum is healthy. Every existing controller shows as
LeaderorFollowerin thedescribe --replicationoutput.The new hosts are reachable from the Ansible host and from the existing controllers on the controller port, which defaults to
9093.
To add controllers:
Add the new hosts at the end of the
kafka_controllergroup in the inventory file, with the same settings as the existing controllers. You don’t need to change anything else in the inventory.If
node_idis not set, Confluent Ansible works out the node ID of each controller from its position in the group. Inserting a host earlier in the list changes the node IDs of the controllers after it, and they fail to start.Run the controller playbook for the new controllers only:
ansible-playbook -i hosts.yml confluent.platform.kafka_controller \ --limit kcontroller-4.example.com,kcontroller-5.example.com
With
--limit, Confluent Ansible installs and starts only the new controllers. It doesn’t restart the existing controllers.Without
--limit, Confluent Ansible also updatescontroller.quorum.bootstrap.serverson the existing controllers so that it lists the new hosts, and restarts them one at a time. This is not required, because controllers learn the voters from the metadata log.
Confluent Ansible doesn’t restart the brokers in either case. A broker needs only one reachable controller in its
controller.quorum.bootstrap.serverslist.Verify that every controller, old and new, is a voter:
kafka-metadata-quorum --bootstrap-controller <controller-host>:<controller_port> \ --command-config /etc/controller/client.properties describe --replication kafka-metadata-quorum --bootstrap-controller <controller-host>:<controller_port> \ --command-config /etc/controller/client.properties describe --status
A new controller can show as
Observerfor a short time while it catches up.Check that every controller has the same
cluster.id. Run the following command on each controller:grep cluster.id /var/lib/controller/data/meta.properties
Replace a controller
To replace a controller whose host or disk is lost, remove the old controller from the quorum as described in Remove controllers, and then add the new host as described in Add controllers. You can reuse the old inventory hostname.
Troubleshoot added controllers
- A new controller stays an observer
Check that it caught up with the leader, that it can reach the other controllers on the controller port, and that
controller.quorum.auto.join.enable=trueis in itsserver.propertiesfile. If you disabled auto-join, run the following command on the new controller:kafka-metadata-quorum --bootstrap-controller <leader-host>:<controller_port> \ --command-config /etc/controller/server.properties add-controller
- A new controller fails to start with
INCONSISTENT_CLUSTER_ID The storage of the controller was formatted for a different cluster, for example by a manual
kafka-storage format. Stop the controller, empty its data directory, which defaults to/var/lib/controller/data, and run the controller playbook for that host again.
Remove controllers
Removing a controller is a manual procedure with kafka-metadata-quorum
remove-controller. Confluent Ansible doesn’t
automate it.
Before you remove a controller, consider the following:
Remove one controller at a time and check the quorum after each one.
Keep enough voters running. Count the voters that are up, not only the voters in the voter set. Removing a running voter while another one is down can leave the quorum without a majority.
To replace a controller, remove the old controller first and then add the new one.
Run the following steps for one controller at a time. The commands assume a package installation with Confluent Ansible defaults. Adapt the paths and service names for archive installations, custom users, or rootless deployments.
On any remaining controller, find the node ID and directory ID of the controller to remove:
kafka-metadata-quorum --bootstrap-controller <remaining-controller>:<controller_port> \ --command-config /etc/controller/client.properties describe --replication
Note the
NodeIdandDirectoryIdfrom the same row of the output.If the host is lost, it is already down. Confirm that it is down, and then skip this step. Otherwise, on the controller you are removing, stop and disable KRaft:
sudo systemctl disable --now confluent-kcontroller
If you changed the service name, use the value of
kafka_controller_service_nameinstead ofconfluent-kcontroller.The controller must stay stopped. Auto-join adds any running, caught-up controller back to the voter set. If you remove a controller that is still running, or leave a removed host in the inventory so the next playbook run starts it again, auto-join adds it back.
On any remaining controller, remove the controller from the quorum:
kafka-metadata-quorum --bootstrap-controller <remaining-controller>:<controller_port> \ --command-config /etc/controller/client.properties \ remove-controller --controller-id <node-id> --controller-directory-id <directory-id>
If the removed controller was the leader, the remaining voters elect a new leader.
Check the quorum. The removed controller must no longer be listed as
LeaderorFollower:kafka-metadata-quorum --bootstrap-controller <remaining-controller>:<controller_port> \ --command-config /etc/controller/client.properties describe --replication kafka-metadata-quorum --bootstrap-controller <remaining-controller>:<controller_port> \ --command-config /etc/controller/client.properties describe --status
Update the inventory file:
Pin the node IDs first. If
node_idis not set, Confluent Ansible works out the node ID of each controller from its position in thekafka_controllergroup, such as9991and9992. Removing a host from the middle of the list gives every controller after it a different node ID on the next playbook run, and those controllers fail to start. On every controller you keep, setnode_idto its current node ID from the first step.Delete the removed hosts from the
kafka_controllergroup.
If the host is not lost, decommission it after the previous step confirms it is out of the quorum. A retired host still holds its KRaft data, including the cluster ID and its node ID. If the service starts on it again, for example after a reboot, a playbook run with an old inventory, or reuse of the machine, it tries to rejoin the cluster and auto-join adds it back as a voter. Delete the controller data so that the host has nothing to rejoin with:
sudo rm -rf /var/lib/controller/data/*
The service is already stopped and disabled.
Troubleshoot removed controllers
- The removed controller shows up as a voter again
The controller was still running or was started again, and auto-join added it back. Stop and disable it, remove it from the inventory, and run the
remove-controllercommand again.remove-controllerfails with an unknown voter or wrong directory IDThe
NodeIdandDirectoryIdmust come from the same row of thedescribe --replicationoutput. Run thedescribe --replicationcommand again and copy both values from the same line.- Controllers fail to start after you remove a host from the inventory
node_idwas not pinned, so removing a host from the middle of thekafka_controllergroup changed the node IDs of the controllers after it. Setnode_idon each controller back to the node ID stored on its disk, which isnode.idin/var/lib/controller/data/meta.properties, and then run the controller playbook again.- A controller host is lost and cannot be stopped
A lost host is already stopped. From a remaining controller, find the node ID and directory ID, remove the controller, and check the quorum. The dead controller is listed with a
LastFetchTimestampthat stops moving and a growingLag. Lag alone does not mean a controller is gone, so confirm by other means that the host is down.
Recover from controller loss
Use this procedure when a cluster with a dynamic quorum loses controllers, for
example when a region becomes unavailable. The recovery is manual. You run
kafka-metadata-recovery and kafka-metadata-quorum on the surviving
hosts.
The quorum can elect a leader and accept metadata writes only while more than half of the voters are running. If half or more of the voters are unavailable, the quorum is lost. With no controller leader, no metadata changes are possible. You can’t change topics, move partition leaders, or add brokers. The recovery builds a new quorum from the surviving controllers. Until you restore the failed hosts, the cluster runs on a smaller quorum with less fault tolerance.
For example, a two-region cluster with three controllers in each region has six voters. If two voters are unavailable, four are still running and the quorum keeps working. If you lose one region, only three voters remain. Three isn’t more than half of six, so the quorum is lost.
Choose a procedure
Run the following command on any surviving controller to check whether the quorum still has a leader:
kafka-metadata-quorum --bootstrap-controller <controller-host>:<controller_port> \
--command-config /etc/controller/client.properties describe --status
Result |
Procedure |
|---|---|
The command returns a |
No action is needed. |
The command returns a |
Follow Some controllers are unavailable and the quorum is healthy. |
The command times out and exactly half of the voters survive. |
Follow Recover the quorum. The recovery point objective (RPO) is zero. |
The command times out and fewer than half of the voters survive. |
Follow Recover the quorum. You can lose metadata. |
Quorum loss, data safety, and RPO
The RPO is how much committed data you can lose in a recovery. An RPO of zero means that you lose no committed data. A metadata write counts as committed only after more than half of the voters store it.
If exactly half of the voters survive, every committed metadata write reached at least one surviving controller. Rebuilding the quorum loses no metadata. This case is possible only with an even number of voters.
If fewer than half of the voters survive, a committed metadata write can exist only on failed controllers. Rebuilding the quorum can lose that metadata.
The recovery only changes metadata in the __cluster_metadata log. It does
not change topic data on the brokers.
The recovery rebuilds the new quorum from one surviving controller, called the seed. Choose the seed by the highest metadata epoch first. Break ties by the largest log end offset. Don’t choose the seed by log end offset alone, because a longer log from an older epoch can be a stale copy that is missing committed writes.
Before you begin
Confluent Platform 8.4.0 or later, deployed with Confluent Ansible.
kraft_dynamic_quorum_enabled: trueis set. You either deployed the cluster with a dynamic quorum or migrated it as described in Migrate a static quorum to a dynamic quorum.Confluent Ansible enables auto-join by default. Keep it enabled, because recovered controllers rejoin the quorum through auto-join.
The inventory file that you used to deploy the cluster.
SSH access to every surviving controller and broker.
Free disk space on each surviving controller for one copy of its
__cluster_metadata-0folder.
Test this procedure on a staging cluster that matches your production layout before you need it. A trial run finds problems with DNS, certificates, firewalls, and custom paths while there is no time pressure.
Identify the failed hosts
While the quorum has no leader, Kafka can’t tell you which voters are unavailable. Identify the failed hosts from your infrastructure, such as the cloud console, the hypervisor, or datacenter status.
Keep the failed hosts offline
The recovery creates a new metadata history, so the failed hosts must stay offline until you finish Phase 1. If the failed controllers recover and can reach each other, they can form a second quorum on the old history. This results in split-brain, where two leaders accept different metadata changes for the same cluster.
Confluent Ansible enables the Kafka services at boot, so a failed host that powers back on starts Kafka by itself. As soon as you can reach a failed host, and before it can reach the rest of the cluster, stop and disable Kafka on it:
sudo systemctl disable --now confluent-kcontroller # controllers
sudo systemctl disable --now confluent-server # brokers
Bring the failed hosts back only with Phase 2, which clears their old metadata first.
Snapshot the controller disks
The step that rebuilds the voter set can’t be undone. Before Phase 1, take a
disk-level snapshot of the metadata disk of each surviving controller. The
default location is /var/lib/controller. The snapshot is your rollback if
something goes wrong. The recovery steps also copy __cluster_metadata-0 to a
backup folder on each surviving controller before they change anything.
Recover the quorum
The commands assume a package installation with Confluent Ansible defaults.
Item |
Default |
|---|---|
Controller service |
|
Controller configuration |
|
Controller admin client configuration |
|
Controller metadata folder |
|
Controller port |
|
Broker service |
|
Broker metadata folder |
|
Service user |
|
Archive installations, custom users, and rootless deployments use different paths and service names. Adapt the commands to your setup.
Note
Run kafka-metadata-recovery as the service user, which is cp-kafka by
default. If you run it as root, give ownership of
/var/lib/controller/data/__cluster_metadata-0 back to the service user
before you start KRaft by running the following command:
sudo chown -R cp-kafka:confluent /var/lib/controller/data/__cluster_metadata-0
Phase 1: Recover the surviving controllers
On every surviving controller, complete the following steps:
Stop KRaft:
sudo systemctl stop confluent-kcontroller
Back up the metadata log:
TS=$(date +%s) sudo mkdir -p /var/lib/controller/kraft-quorum-recovery-backup/$TS sudo cp -a /var/lib/controller/data/__cluster_metadata-0 /var/lib/controller/kraft-quorum-recovery-backup/$TS/
Read the epoch and the log end offset. The tool needs a
.lockfile in the metadata folder, and a stopped controller may not have one.sudo -u cp-kafka bash -c '[ -f /var/lib/controller/data/.lock ] || : > /var/lib/controller/data/.lock' sudo -u cp-kafka kafka-metadata-recovery reconfig log-length --metadata-log-dir /var/lib/controller/data
Example output:
epoch: 12, log end offset: 48213
Pick the seed. Choose the controller with the highest epoch. Use the largest log end offset only to break a tie. Never pick by offset alone.
On the seed only, rebuild the voter set. This step can’t be undone. Run it exactly once.
If secrets protection is enabled, the tool needs the master key to read
server.properties:MASTER_KEY=$(sudo grep -oP 'CONFLUENT_SECURITY_MASTER_KEY=\K[^"]+' \ /etc/systemd/system/confluent-kcontroller.service.d/override.conf) sudo -u cp-kafka env CONFLUENT_SECURITY_MASTER_KEY="$MASTER_KEY" \ kafka-metadata-recovery reconfig force-standalone --config /etc/controller/server.properties
If secrets protection isn’t enabled, run the command without the
MASTER_KEYline and theenvpart:sudo -u cp-kafka kafka-metadata-recovery reconfig force-standalone --config /etc/controller/server.properties
Warning
If the command fails or is interrupted, stop. Don’t run it again. Contact Confluent Support.
On the seed, start KRaft and confirm that it is the only voter and the leader:
sudo systemctl start confluent-kcontroller kafka-metadata-quorum --bootstrap-controller <seed-host>:<controller_port> \ --command-config /etc/controller/client.properties describe --status
LeaderIdmust be the node ID of the seed, andCurrentVotersmust list only the seed.On each of the other surviving controllers, one at a time, delete the old metadata log and start KRaft. Keep the backup that you made in step 1. The
meta.propertiesfile stays, so the controller keeps its node ID and directory ID.sudo rm -rf /var/lib/controller/data/__cluster_metadata-0 sudo systemctl start confluent-kcontroller
The controller starts as an observer and copies the log from the seed. Auto-join then promotes it to a voter. Wait until the controller shows as
Followerbefore you move to the next one:kafka-metadata-quorum --bootstrap-controller <seed-host>:<controller_port> \ --command-config /etc/controller/client.properties describe --replication
If a controller stays an observer, promote it. Run the following command on that controller. The tool reads the node ID and directory ID from the local configuration:
kafka-metadata-quorum --bootstrap-controller <seed-host>:<controller_port> \ --command-config /etc/controller/server.properties add-controller
On each surviving broker, check that it shows as an observer that is catching up with the seed. No change is needed on the brokers.
kafka-metadata-quorum --bootstrap-controller <seed-host>:<controller_port> \ --command-config /etc/controller/client.properties describe --replication
If a broker doesn’t show as an observer that is catching up, contact Confluent Support before you change anything on it. This can happen after a recovery where fewer than half of the voters survived. The broker can hold a metadata change that the surviving controllers lost.
Phase 1 is complete. The cluster now runs on the surviving controllers.
Phase 2: Restore the failed hosts
Start Phase 2 only after Phase 1 is complete and the new quorum is healthy.
The failed controllers still hold metadata from before the rebuild. Each
returning controller must have its old __cluster_metadata-0 removed before
KRaft starts.
Power on the failed controllers one at a time. Each one still has the old voter set. If more than half of the old voter set starts together, they can elect a leader on the old history. Finish steps 1 and 2 on one controller before you power on the next one.
On each returning host, as soon as you can reach it, make sure that Kafka is stopped and disabled:
sudo systemctl disable --now confluent-kcontroller # controllers sudo systemctl disable --now confluent-server # brokers
On each returning controller, one at a time, move the old metadata log aside and start KRaft:
TS=$(date +%s) sudo mkdir -p /var/lib/controller/kraft-quorum-recovery-backup/$TS sudo mv /var/lib/controller/data/__cluster_metadata-0 /var/lib/controller/kraft-quorum-recovery-backup/$TS/ sudo systemctl start confluent-kcontroller
Wait until the controller shows as
Followerin thedescribe --replicationoutput, and then do the next one.On each returning broker, one at a time, start Kafka:
sudo systemctl start confluent-server
Wait until the broker shows as an observer that is catching up and its partitions are back in sync, and then do the next one. If it doesn’t catch up, contact Confluent Support.
On each returning host, enable Kafka at boot again:
sudo systemctl enable confluent-kcontroller # controllers sudo systemctl enable confluent-server # brokers
If exactly half of the voters survived, the metadata that you moved aside on the returning controllers holds nothing that the survivors don’t already have. If fewer than half survived, it can hold the only copy of metadata that was lost. Keep it until you have checked.
Replace a host that doesn’t recover
If the machine or disk of a failed controller is gone for good, it can’t rejoin. Replace it instead:
If the quorum stayed healthy, remove the old controller from the voter set as described in Remove controllers. If you rebuilt the quorum in Phase 1, skip this step, because the lost controller is no longer a voter.
Provision the new host with the same inventory hostname, or update the inventory file.
Run the controller playbook for that host only:
ansible-playbook -i hosts.yml confluent.platform.kafka_controller --limit <new-controller-host>
Confluent Ansible sees that the other controllers are already formatted. It formats the new host as an observer with
--no-initial-controllers, and auto-join makes it a voter. Confluent Ansible doesn’t restart existing controllers.
Replace lost brokers with the kafka_broker playbook, also with --limit.
For the full procedures, see Remove controllers and Add controllers.
Verify the recovery
Run the following commands to confirm that the cluster is healthy:
# Quorum status shows a LeaderId and the expected CurrentVoters.
kafka-metadata-quorum --bootstrap-controller <controller-host>:<controller_port> \
--command-config /etc/controller/client.properties describe --status
# Every expected controller is Leader or Follower, with low Lag.
kafka-metadata-quorum --bootstrap-controller <controller-host>:<controller_port> \
--command-config /etc/controller/client.properties describe --replication
# No partitions are under-replicated or offline.
kafka-topics --bootstrap-server <broker-host>:<port> \
--command-config /etc/kafka/client.properties --describe --under-replicated-partitions
kafka-topics --bootstrap-server <broker-host>:<port> \
--command-config /etc/kafka/client.properties --describe --unavailable-partitions
# Metadata writes work. Create and delete a test topic.
kafka-topics --bootstrap-server <broker-host>:<port> \
--command-config /etc/kafka/client.properties --create --topic dr-check --partitions 1 --replication-factor 3
kafka-topics --bootstrap-server <broker-host>:<port> \
--command-config /etc/kafka/client.properties --delete --topic dr-check
If secrets protection is enabled, the client.properties file on the broker is
encrypted. Export CONFLUENT_SECURITY_MASTER_KEY before you run
kafka-topics. You can find the value in
/etc/systemd/system/confluent-server.service.d/override.conf. The
client.properties file on the controller isn’t encrypted.
Clean up after recovery
Keep the metadata backups until you have verified the recovery. They let you inspect what the recovery replaced. If metadata loss was possible, a backup can hold the only copy of a lost change. After the full quorum is healthy and you have checked the recovery point, free the space on each controller:
sudo rm -rf /var/lib/controller/kraft-quorum-recovery-backup
Also delete the disk snapshots that you took before the recovery. Don’t clean up until you have fully verified the recovery.