Skip to content

Add support for broker demotion - #191

Open
kyguy wants to merge 7 commits into
strimzi:mainfrom
kyguy:kr-demote-brokers
Open

Add support for broker demotion#191
kyguy wants to merge 7 commits into
strimzi:mainfrom
kyguy:kr-demote-brokers

Conversation

@kyguy

@kyguy kyguy commented Jan 13, 2026

Copy link
Copy Markdown
Member

Related problem

When preparing to remove or decommission brokers from a Kafka cluster there is currently no built-in way to ensure those brokers are first demoted (no longer eligible to act as partition leaders). This can result in partitions becoming temporarily unavailable or degraded when those brokers are taken offline, especially in clusters with uneven leadership distribution. Having a mechanism to programmatically demote brokers would allow for safer, more predictable operations during maintenance or scaling events.

Suggested solution

This feature would extend the KafkaRebalance resource to leverage Cruise Control’s /kafkacruisecontrol/demote_broker endpoint [1], allowing users to specify a list of brokers to be demoted. This would trigger the migration of partition leadership away from those brokers in preparation for decommissioning or maintenance.

Addresses issue discussed here [2]

[1] https://github.com/linkedin/cruise-control/wiki/REST-APIs#demote-a-list-of-brokers-from-the-kafka-cluster
[2] strimzi/strimzi-kafka-operator#11907

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
@kyguy
kyguy force-pushed the kr-demote-brokers branch from 7fc8acd to abb52f1 Compare January 13, 2026 22:11
@kyguy
kyguy marked this pull request as ready for review January 13, 2026 22:12

@see-quick see-quick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the proposal, I think it looks good, just a few nits/questions...

Out of curiosity, I didn't find it in the proposal but what happens when demotion is in progress but target broker fails in the middle of operation?

Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
@kyguy

kyguy commented Jan 14, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review @see-quick

Out of curiosity, I didn't find it in the proposal but what happens when demotion is in progress but target broker fails in the middle of operation?

I just added this note to the Validation and constraints section of the proposal:

"If a target broker fails while leadership is being transferred to it, all demotion operations involving that broker are aborted, and the source brokers remain the leaders for the affected partitions.
In this case, the overall demotion request continues on a best-effort with the proposed operations, transferring the leadership on brokers that are available."

@kyguy
kyguy force-pushed the kr-demote-brokers branch from d308e3a to 07cf465 Compare January 14, 2026 18:06
Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>

@fvaleri fvaleri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kyguy. I left some comments.

I think it is also important to document that broker demotion does NOT prevent new partition leaders to be scheduled on the selected broker.

Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated

@tinaselenge tinaselenge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the proposal. Overall, it looks good to me. I left a few comments to clarify.

Comment thread 128-broker-demotion-support.md Outdated
| brokers | integer array | List of ids of broker to be demoted in the cluster. |
| concurrentLeaderMovements | integer | Upper bound of ongoing leadership swaps. Default is 1000. |
| skipUrpDemotion | boolean | Whether to skip demoting leader replicas for under-replicated partitions. |
| excludeFollowerDemotion | boolean | Whether to skip demoting follower replicas on the broker to be demoted. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does demoting follower replicas mean?

@kyguy kyguy Jan 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It moves the ids of the demoted brokers to the end of the replica lists.

Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
# Broker demotion support via KafkaRebalance resource

This proposal extends the `KafkaRebalance` custom resource to support broker demotion by integrating with Cruise Control's `/demote_broker` endpoint.
This would allow users to demote brokers, removing them from partition leadership eligibility, in preparation for maintenance, decommissioning, or other operational needs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work? I get it that it removes them from partition leadership. But how does it ensure they are not eligible to become leaders again?

@kyguy kyguy Jan 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cruise Control has the broker ids marked as ineligible in memory and moves the broker ids to the end of the replica lists, then triggers a leadership election. Since leadership election prioritizes choosing the first broker id of the replica list (the preferred leader) as the leader, the demoted brokers are less likely to be elected as leaders.

But how does it ensure they are not eligible to become leaders again?

If a rebalance or demotion request is made the broker ids marked as ineligible in memory are excluded from having partitions moved to them or being listed first in the replica lists.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when CC pod is restarted (upgrade, migration to different node, etc).? User will have to trigger "rebalance" proposal and approval to refresh in-memory data?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this time yes, to refresh the in-memory demotion data after Cruise Control pod restart, a user would have to trigger another KafkaRebalance demotion request.

Comment thread 128-broker-demotion-support.md Outdated
Comment on lines +76 to +78
**NOTE**: As part of this proposal, we will also add a `excludeRecentlyDemotedBrokers` field for the `full`, `add-brokers`, and `remove-brokers` KafkaRebalance modes to give users the ability to prevent to leader replicas to be moved to recently demoted brokers.
When `excludeRecentlyDemotedBrokers` is set to `true`, a broker is considered demoted for the duration specified by the Cruise Control `demotion.history.retention.time.ms` server configuration.
By default, this value is 1209600000 milleseconds (14 days) but is configurable in the `spec.cruiseControl.config` section of the `Kafka` custom resource.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work? Where is the information about the demotion work?

@kyguy kyguy Jan 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cruise Control stores the demotion information in memory (yes this is far from ideal). Cruise Control will make sure the ids of the demoted brokers are in the end of the replica lists and will exclude the brokers from being considered for partition movement when generating optimization proposals.

Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated

The implementation includes the following validation:

* When `demote-brokers` mode is specified, the `brokers` field must be provided.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will it be validated only in the broker code or also with CEL?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was originally planning on validating the field in the operator code but this may change depending on the proposal surrounding the API changes discussed #191 (comment).

I'll link the separate proposal here when I have a draft ready and we can pick this up once that proposal and its implementation is sorted.

Comment thread 128-broker-demotion-support.md Outdated
Comment thread 128-broker-demotion-support.md Outdated
kyguy added 2 commits January 27, 2026 19:50
Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
@kyguy

kyguy commented Jan 29, 2026

Copy link
Copy Markdown
Member Author

Thanks everyone for the reviews! I am putting this proposal on hold temporarily as we address some of the API concerns raised in the thread here: #191 (comment). We need devise a better path forward for the parameters that are used in conjunction with mode field of the KafkaRebalance resource, maybe by consolidating primitive fields into a generic config section to ensure the API can support future modes cleanly.

I am going to draft a separate proposal for those API changes and link it here. Once that proposal and its implementation is complete, we can continue this broker demotion proposal with a cleaner, more maintainable foundation.

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
Comment thread 128-broker-demotion-support.md
@kyguy

kyguy commented Apr 8, 2026

Copy link
Copy Markdown
Member Author

I am going to draft a separate proposal for those API changes and link it here. Once that proposal and its implementation is complete, we can continue this broker demotion proposal with a cleaner, more maintainable foundation.

Opened a draft proposal for the KafkaRebalance API changes here #216. We can follow up on the conversation there and return to this proposal once the proposal is reviewed and implemented.

Signed-off-by: Kyle Liberti <kliberti.us@gmail.com>
@kyguy
kyguy force-pushed the kr-demote-brokers branch from 146e85f to cf20628 Compare August 28, 2026 23:04
@kyguy

kyguy commented Aug 28, 2026

Copy link
Copy Markdown
Member Author

This proposal has been updated with the new KafkaRebalance API design as specified in the accepted proposal: #216), is unblocked, and ready for review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants