Maintenance Mode
Maintenance mode allows you to safely take brokers offline for upgrades, hardware maintenance, or decommissioning. Pilot moves all partitions off the brokers, and the next proposal after maintenance ends moves partitions back onto them.
How It Works
- Enter maintenance - Pilot generates a plan to move all partitions (leaders and replicas) off one broker, or off several brokers in one operation
- Execute moves - partitions are reassigned to other brokers with throttle management
- Brokers are empty - the drained brokers have no partition assignments and can be safely stopped
- Exit maintenance - each broker is marked online again. The next proposal includes it as a target and moves partitions back to bring it to its fair share. See Refill After Maintenance
API Endpoints
| Method | Path | Description | License |
|---|---|---|---|
POST | /api/v1/brokers/maintenance | Drain one or more brokers into maintenance mode | Apply only |
POST | /api/v1/brokers/{brokerId}/maintenance | Drain one broker (older endpoint, see below) | Apply only |
DELETE | /api/v1/brokers/{brokerId}/maintenance | Exit maintenance mode | Yes |
A preview ("preview": true) needs no license; starting a drain needs a valid license and returns 403 without one. See the OpenAPI specification for request and response schemas.
POST /api/v1/brokers/{brokerId}/maintenance is the older endpoint for a single broker. It runs fewer checks: it does not refuse rack collapses or unusable target brokers. Prefer POST /api/v1/brokers/maintenance.
Enter Maintenance
curl -X POST http://localhost:8080/api/v1/brokers/maintenance \
-H "Content-Type: application/json" -d '{"brokerIds": [3]}'This triggers a proposal to evacuate all partitions from broker 3, then executes it with managed throttling. Pilot checks the request first; see Drain Checks.
Drain Several Brokers at Once
POST /api/v1/brokers/maintenance drains a set of brokers in one operation: every replica on them moves once, straight to its final broker. Draining the brokers one after the other can move a replica twice, for example from broker 1 onto broker 4 and then off it again.
To drain brokers 1 and 4 onto brokers 7 and 9, preview the plan first:
curl -X POST http://localhost:8080/api/v1/brokers/maintenance \
-H "Content-Type: application/json" \
-d '{"brokerIds": [1, 4], "targetBrokers": [7, 9], "preview": true}'A preview runs the checks and changes nothing. It returns the planned partition changes, what each receiving broker gets (targetSummary), how balanced the cluster lands (landing, see Choose Target Brokers), and any warnings. Data estimates leave out partitions Pilot has not measured yet.
Then start the drain with the same brokers and targets:
curl -X POST http://localhost:8080/api/v1/brokers/maintenance \
-H "Content-Type: application/json" \
-d '{"brokerIds": [1, 4], "targetBrokers": [7, 9]}'Pilot marks brokers 1 and 4 as in maintenance and moves their partitions as one monitored operation with strategy MAINTENANCE-BROKER-1,4, shown as Brokers 1, 4 Maintenance under Execution. The response returns as soon as the drain starts.
Large Drains
A drain always moves every partition; only its response is bounded. changesLimit limits partitionChanges: omitted lists every change and 0 none. With N, a plan of more than N changes lists its N heaviest, heaviest first; a smaller plan lists every change. The other lists stop at 1000 entries. Each list has a total field beside it, and targetSummary is always complete.
Choose Target Brokers
A drain moves only the replicas on the drained brokers, and changes leadership only where a drained or offline broker leads. Pilot places each new replica by the loads that proposals balance (leaders, followers, disk and client traffic), on a rack the partition does not use yet where possible, so the cluster lands balanced. Without target brokers, every online broker outside the drain and maintenance can receive replicas; target brokers limit the placement to the brokers you name.
- UI - on the Brokers page, choose Maintenance in a broker’s actions. The dialog starts with that broker, and Add brokers drains more. Under Move data to, Automatic uses every eligible broker and Chosen brokers only the brokers you select; drained, offline and in-maintenance brokers cannot be chosen. The plan updates with each change and lists the 200 heaviest partition changes beside the totals. Set to Maintenance starts the drain; without a valid license the dialog still shows the plan, and the button stays disabled. If the drain needs
force, the dialog lists the affected partitions and offers a checkbox to drain anyway, and the button reads Force Set to Maintenance. The UI drains throughPOST /api/v1/brokers/maintenance. - REST API -
targetBrokersin the request body. Pilot refuses a target that is also drained (400, reasoninvalid_request) or that is in maintenance, offline or not in the cluster (409, reasoninvalid_target). - MCP -
set_broker_maintenancetakesbrokerIds(orbrokerIdfor one broker) and optionaltargetBrokers, with the checks ofPOST /api/v1/brokers/maintenance. It never forces: a refused drain returnsstatus: "blocked"with areason. Force a drain from the UI or the REST API.
A partition led by a drained or offline broker gets a new leader, chosen by the same loads from its in-sync replicas outside the drain and its new replicas.
landing in the response predicts how balanced the cluster is after the drain. balanced is true when every broker ends within 10% (by default) of its fair share of every load and no topic is concentrated. The UI then shows Lands balanced. Otherwise it names the loads that stay uneven. A drain moves only what it must, so some unevenness can remain, mostly in small clusters or with few target brokers. The next proposal evens it out. Without a metrics reading yet, landing is null. A live drain plans again on current rates, so it can differ slightly from its preview.
Drain Checks
POST /api/v1/brokers/maintenance checks the request and its plan before anything moves. A refused request returns success: false, an error message and a reason, with the partitions or brokers concerned:
reason | Status | Meaning | force overrides |
|---|---|---|---|
invalid_request | 400 | Malformed body, no broker, a negative ID or changesLimit, or a target that is also drained | - |
unknown_broker | 400 | A broker is not in the cluster and holds no replicas. A broker that is down but still holds replicas can be drained | - |
rolling_restart_active | 409 | A rolling restart is in progress | - |
already_in_maintenance | 409 | A broker to drain is already in maintenance | - |
reassignments_in_flight | 409 | Kafka is still moving a partition with a replica on a drained broker, also when another tool started the move. The response lists them in partitions | Never |
reassignment_status_unavailable | 409 | Pilot could not read from Kafka whether those partitions are moving. Retry in a moment | Never |
moves_found_at_startup | 409 | Moves Pilot found at startup are still running. Live drains only | Never |
checking_partition_moves | 409 | Pilot is still checking which moves were in progress at startup. Live drains only | Never |
invalid_target | 409 | A target broker is in maintenance, offline or not in the cluster | - |
no_eligible_targets | 409 | No online broker outside the drain and maintenance can receive replicas | - |
rf_shortfall | 409 | A partition would lose replicas. See Force and Replication Factor | Yes |
rack_collapse | 409 | A partition would spread over fewer racks. See Rack Collapses | Yes |
below_min_isr | 409 | A partition would have fewer replicas than its min.insync.replicas | Never |
hard_health | 409 | The cluster is unhealthy. Live drains only | Never |
operation_in_progress | 409 | Another reassignment operation is running. Live drains only | Never |
A preview runs every check except those for live drains only. When a plan falls short of the replication factor and the forced plan would still leave a partition below min.insync.replicas, the reason is below_min_isr rather than rf_shortfall, since force cannot help. MCP runs the same checks on its drains.
Force and Replication Factor
A drain preserves each partition’s replication factor by moving its replicas to other brokers. If the cluster cannot host a full replica set for one or more partitions without the drained brokers (for example, too few brokers remain outside the drain and maintenance, or the target brokers already hold the partition’s other replicas), the request returns 409 Conflict with reason rf_shortfall and names the affected partitions.
Re-submit with "force": true in the request body to perform an audited reduced-RF drain. The forced drain proceeds for the affected partitions at a lower replication factor:
curl -X POST http://localhost:8080/api/v1/brokers/maintenance \
-H "Content-Type: application/json" -d '{"brokerIds": [3], "force": true}'force performs a reduced-RF drain only where RF cannot be preserved. It also accepts rack collapses. A partition that gets no replica at all stays on the drained brokers and is listed in skippedPartitions. A forced drain is recorded in the audit log as broker.maintenance.set.override.
Rack Collapses
To keep the replication factor, Pilot places a replica on a rack the partition already uses when no other rack has an eligible broker. The partition then spreads over fewer racks, and one rack failure takes more of its replicas.
Pilot refuses a drain that leaves a partition on fewer racks than before (409, reason rack_collapse). The response lists the partitions and uncoveredRacks: racks with drained replicas but no eligible target broker. A partition that keeps as many racks as before does not count, even if two of its replicas share a rack. With force the drain proceeds, and the response lists the partitions in rackCollapses.
Draining every broker of a rack takes that rack away. Partitions with a replica on every rack, such as RF 3 on three racks, then lose a rack, so the drain needs force.
Safety Gating
Maintenance drains run the same live cluster-health pre-flight as other reassignments. Hard-health blockers (controller unhealthy, majority of brokers unavailable, sustained ISR shrink) return 409 Conflict and are not overridable by force. The majority check leaves out brokers in maintenance, also when they are stopped after a drain. Drains are also blocked while a rolling restart is in progress. See Apply-Time Safety Gating.
force never leaves a partition with fewer replicas than its min.insync.replicas (the topic setting, else the broker default), because acks=all writes would stop. Such a drain returns 409 Conflict with reason below_min_isr; lower min.insync.replicas or add brokers first.
After the Drain
A drain ends like every operation that moves partitions; see How Operations End. However it ends, its brokers stay in maintenance. A failed drain is recorded in the audit log.
When the drain’s moves end, Pilot re-reads the cluster metadata and looks for partitions that still have a replica on a drained broker, for example a partition created during the drain or a move that failed or was cancelled. It reports them as the operation’s error under Execution, in the log, and in the audit log as broker.maintenance.residual. An MCP drain also returns them in residualPartitions. Move these partitions, for example with a single-partition reassignment, before you stop the brokers.
Pilot starts no rebalance after a drain. With PILOT_HEAL_ENABLED=true and PILOT_HEAL_DRY_RUN=false, activity self-healing balances the remaining brokers on its own schedule; otherwise review and apply the next proposal.
Exit Maintenance
curl -X DELETE http://localhost:8080/api/v1/brokers/3/maintenancePilot marks the broker as online. Brokers leave maintenance one at a time, also after a drain of several brokers: send one DELETE per broker, or choose Remove Maintenance in each broker’s actions on the Brokers page. Exiting maintenance moves no partitions itself: it invalidates the current proposal and queues a fresh calculation that includes the broker as a target. That proposal moves partitions back onto the broker. Apply it like any other proposal, or let activity self-healing apply it (PILOT_HEAL_ENABLED=true and PILOT_HEAL_DRY_RUN=false).
Refill After Maintenance
The drain’s moves start no 30-minute cooldown, so the first plan after maintenance can move drained partitions back, even when maintenance ends within 30 minutes of the drain. This holds for drains started from the UI, the API, MCP tools and the assistant. Every other move, such as a proposal applied during maintenance, keeps its cooldown. Drain moves still count for settling, so applying the refill can wait until measurements reflect the drained placement.
In standalone mode, cooldowns do not survive a Pilot restart. In HA mode, they survive failovers and restarts.
The refill follows the fair-share rule. A returning broker is far below its fair share of every load, so Pilot evens each load until every broker is within 5% of its fair share. The first plan brings the returning broker to at least 90% of its fair share of most loads. Leaders can take a second, smaller plan. A load that cannot get there is shown at its limit with its cause.
If Pilot Restarts During a Drain
This section describes standalone Pilot. In High Availability mode, the next active replica resumes a drain after a failover.
Maintenance state survives a restart, but the drain does not resume. Moves that Kafka already started run to completion, with the throttles Pilot set. Moves Pilot had not sent yet are not sent. To finish the drain:
- Wait until the moves Kafka is still running finish. Until then Pilot refuses a new drain with
moves_found_at_startuporreassignments_in_flight.kafka-reassign-partitions.sh --bootstrap-server <broker> --listshows the running moves. - Remove maintenance from each drained broker with
DELETE /api/v1/brokers/{brokerId}/maintenance. - Start the drain again right away, with the same brokers and target brokers. It plans only the partitions still on those brokers.
URP-Aware Proposals
Maintenance proposals account for under-replicated partitions (URPs). If moving partitions off a broker would create URPs (e.g., RF=1 topics), the proposal warns about it. When the drain cannot preserve a partition’s replication factor it is reported as described under Force and Replication Factor rather than evacuated silently.
Monitoring
The number of brokers in maintenance is tracked:
pilot_cluster_brokers_maintenanceMaintenance state is persisted to the __pilot_broker_state Kafka topic, so it survives Pilot restarts.