|
| 1 | +<!-- |
| 2 | +Copyright 2026 Adobe. All rights reserved. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | +# Broker autoscaling |
| 18 | + |
| 19 | +Koperator can add or remove a data broker in response to an alert delivered to |
| 20 | +its action receiver. Prometheus evaluates your policy, Alertmanager routes the |
| 21 | +action alert, and Koperator updates the KafkaCluster's desired broker list. |
| 22 | +Reconciliation and Cruise Control perform the resource and replica changes. |
| 23 | + |
| 24 | +**Broker autoscaling is opt-in.** The |
| 25 | +[monitoring sample](../config/samples/kafkacluster-prometheus.yaml) contains |
| 26 | +diagnostic broker alerts without scaling commands or broker-action routes. |
| 27 | +These sample defaults do not disable existing custom action alerts, direct |
| 28 | +webhook integrations, or manual changes to `spec.brokers`. |
| 29 | + |
| 30 | +Set up metrics and human notifications using the |
| 31 | +[monitoring user guide](monitoring.md) before enabling broker actions. |
| 32 | +Keep the Helm setting `alertManager.enable` enabled and ensure Alertmanager can |
| 33 | +reach Koperator's webhook Service. Cruise Control must be configured and healthy. |
| 34 | + |
| 35 | +## Prepare a scaling policy |
| 36 | + |
| 37 | +Use a policy validated against your workload and deployment. The sample |
| 38 | +request-rate and partition-count thresholds are not capacity recommendations. |
| 39 | + |
| 40 | +Before enabling actions: |
| 41 | + |
| 42 | +1. Measure idle and representative load behavior per broker: CPU, memory, disk, |
| 43 | + network, request latency, replication health, and partition placement. |
| 44 | +2. Verify that adding a broker produces useful replica redistribution with |
| 45 | + your Cruise Control goals and load model. |
| 46 | +3. Before scale-in, verify that the remaining data brokers can sustain the |
| 47 | + workload and preserve replication factor, minimum ISR, and rack placement. |
| 48 | +4. Define a post-operation stabilization interval and prevent opposing |
| 49 | + scale-out/scale-in requests during it. |
| 50 | +5. Test the policy and delivery path in a disposable cluster before production. |
| 51 | + Include missing metrics, broker startup, skew, and overlapping signals. |
| 52 | + |
| 53 | +Koperator does not provide a timed cooldown. An alert's `for` duration measures |
| 54 | +how long its expression remains true, not how long it has been since the last |
| 55 | +operation. Enforce stabilization in your action policy or external coordinator; |
| 56 | +keep scale-in manually approved until that control is in place. |
| 57 | + |
| 58 | +## Configure broker-count limits |
| 59 | + |
| 60 | +Set positive limits in the existing KafkaCluster manifest. This example allows |
| 61 | +three to four data brokers alongside three dedicated KRaft controllers; it is |
| 62 | +not a capacity recommendation: |
| 63 | + |
| 64 | +```yaml |
| 65 | +spec: |
| 66 | + alertManagerConfig: |
| 67 | + downScaleLimit: 6 |
| 68 | + upScaleLimit: 7 |
| 69 | +``` |
| 70 | +
|
| 71 | +Scale-in is skipped when the number of entries in `spec.brokers` is at or below |
| 72 | +`downScaleLimit`. Scale-out is skipped when that count is at or above |
| 73 | +`upScaleLimit`. Omitted or non-positive values do not provide an effective |
| 74 | +bound. |
| 75 | + |
| 76 | +The count includes dedicated KRaft controllers. These limits apply to |
| 77 | +alert-triggered scaling, not manual edits of the broker list. Count limits alone |
| 78 | +do not establish replication, placement, or resource safety. |
| 79 | + |
| 80 | +## Define separate action alerts |
| 81 | + |
| 82 | +Keep diagnostic alerts unchanged. Create separately named action alerts with |
| 83 | +workload-specific conditions or an approval mechanism. |
| 84 | + |
| 85 | +An action alert must contain `namespace` and `kafka_cr` labels and a supported |
| 86 | +`command` annotation. For example, an approved scale-out alert delivered to |
| 87 | +Koperator can carry: |
| 88 | + |
| 89 | +```yaml |
| 90 | +labels: |
| 91 | + alertname: KafkaScaleOutApproved |
| 92 | + namespace: kafka |
| 93 | + kafka_cr: kafka |
| 94 | + autoscaling: approved |
| 95 | +annotations: |
| 96 | + command: upScale |
| 97 | + brokerConfigGroup: broker |
| 98 | +``` |
| 99 | + |
| 100 | +This is an alert payload fragment, not a complete PrometheusRule. Prometheus |
| 101 | +sets `alertname` from the rule's `alert` field. The `autoscaling` label is an |
| 102 | +example routing convention, not a Koperator authorization check; restrict who |
| 103 | +can create action rules and access the webhook. |
| 104 | + |
| 105 | +For scale-out, `brokerConfigGroup` must name an existing configuration group |
| 106 | +suitable for a data broker. In KRaft mode, include the appropriate broker |
| 107 | +process role in that group. Without a matching group, Koperator builds the |
| 108 | +broker configuration from the alert's `image`, `storageClass`, `mountPath`, |
| 109 | +and `diskSize` annotations; provide valid image and storage settings. |
| 110 | + |
| 111 | +For scale-in, use `command: downScale`. An optional `brokerId` label selects |
| 112 | +that broker. Without it, Cruise Control supplies replica counts and Koperator |
| 113 | +selects a broker with the fewest replicas. Equal minima have no guaranteed |
| 114 | +selection order. Failed lookups or empty maps leave the broker list unchanged. |
| 115 | +Neither explicit selection nor minimum replica count proves removal is safe. |
| 116 | + |
| 117 | +## Route only approved actions to Koperator |
| 118 | + |
| 119 | +In the Alertmanager configuration described in the |
| 120 | +[monitoring guide](monitoring.md#configure-notifications-and-actions), add a |
| 121 | +child route under the existing `route.routes` list: |
| 122 | + |
| 123 | +```yaml |
| 124 | +- receiver: koperator-brokers |
| 125 | + matchers: |
| 126 | + - autoscaling="approved" |
| 127 | + - alertname=~"KafkaScaleOutApproved|KafkaScaleInApproved" |
| 128 | + - namespace="kafka" |
| 129 | + - kafka_cr="kafka" |
| 130 | +``` |
| 131 | + |
| 132 | +Add its receiver to the existing `receivers` list: |
| 133 | + |
| 134 | +```yaml |
| 135 | +- name: koperator-brokers |
| 136 | + webhook_configs: |
| 137 | + - url: http://kafka-operator-alertmanager.kafka.svc:9001/ |
| 138 | + send_resolved: true |
| 139 | +``` |
| 140 | + |
| 141 | +These are configuration fragments: merge them without replacing the existing |
| 142 | +`monitoring` or storage routes and receivers. Adjust names, labels, and the |
| 143 | +webhook address for your installation. Do not route all `alertGroup="kafka"` |
| 144 | +alerts to the action receiver. |
| 145 | + |
| 146 | +Koperator accepts Prometheus alert arrays and Alertmanager webhook envelopes. |
| 147 | +Keep resolved deliveries enabled so an alert can be cleared and a later |
| 148 | +recurrence can be processed. |
| 149 | + |
| 150 | +## What happens after an action |
| 151 | + |
| 152 | +The cluster must be running. Koperator applies the count limits and checks for |
| 153 | +relevant pending or running Cruise Control tasks before changing the broker |
| 154 | +list. |
| 155 | + |
| 156 | +| Action | Desired-state change | Subsequent work | |
| 157 | +|---|---|---| |
| 158 | +| `upScale` | Appends one broker to `spec.brokers`, using an ID one greater than the largest existing ID | Creates its resources and initiates Cruise Control scale-out work | |
| 159 | +| `downScale` | Removes the selected broker from `spec.brokers` | In the normal graceful path for initialized data brokers, evacuates replicas through Cruise Control before deleting the broker pod and associated data PVCs | |
| 160 | + |
| 161 | +Replica movement depends on Cruise Control's goals and available model. |
| 162 | +Check actual placement and movement counts, not only task completion. This |
| 163 | +guide describes data-broker scaling; controller-only removal and removal of |
| 164 | +partially initialized brokers follow different paths. |
| 165 | + |
| 166 | +### Repeated notifications |
| 167 | + |
| 168 | +Koperator identifies an alert by a fingerprint of its labels. Once marked |
| 169 | +processed, repeated notifications for that fingerprint do not continuously add |
| 170 | +or remove brokers. A resolved notification clears the entry. Changing labels |
| 171 | +can create a new fingerprint; changing annotations alone does not. |
| 172 | + |
| 173 | +This state is in memory and is lost on an operator restart. It is not a durable |
| 174 | +exactly-once guarantee or a cooldown. Do not assume a skipped scaling alert is |
| 175 | +queued for execution when other work finishes. |
| 176 | + |
| 177 | +## Verify progress and completion |
| 178 | + |
| 179 | +Select the intended context, namespace, and KafkaCluster: |
| 180 | + |
| 181 | +```sh |
| 182 | +CONTEXT=your-kubernetes-context |
| 183 | +NAMESPACE=kafka |
| 184 | +CLUSTER=kafka |
| 185 | +kubectl --context "$CONTEXT" -n "$NAMESPACE" get kafkacluster "$CLUSTER" -o yaml |
| 186 | +kubectl --context "$CONTEXT" -n "$NAMESPACE" get cruisecontroloperations |
| 187 | +kubectl --context "$CONTEXT" -n "$NAMESPACE" get pods,pvc |
| 188 | +``` |
| 189 | + |
| 190 | +Confirm the requested change in `spec.brokers`, inspect graceful-action states |
| 191 | +in `status.brokersState`, and check the corresponding CruiseControlOperation |
| 192 | +results and operator logs. Verify replica placement, in-sync replicas, and |
| 193 | +producer/consumer availability before allowing another action. |
| 194 | + |
| 195 | +HTTP `202 Accepted` acknowledges the alert payload, not successful scaling. |
| 196 | +Guards can skip an action, and action-handling errors can be logged without |
| 197 | +changing that response. Pod readiness alone is also not proof of completion. |
| 198 | + |
| 199 | +## Pause broker autoscaling |
| 200 | + |
| 201 | +Resolve existing broker-action alerts while resolved deliveries are still |
| 202 | +enabled, then disable their generation and action route. Keep diagnostic |
| 203 | +notifications and any separately approved storage actions active. |
| 204 | + |
| 205 | +Check for pending or running operations. Disabling future alerts does not |
| 206 | +cancel an operation already underway. Do not delete broker pods or PVCs to |
| 207 | +interrupt scaling. |
0 commit comments