이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 21. Using Cruise Control for cluster rebalancing
Cruise Control is an open-source application designed to run alongside Kafka to help optimize use of cluster resources by doing the following:
- Monitoring cluster workload
- Rebalancing partitions based on predefined constraints
Cruise Control operations help with running a more balanced Kafka cluster that uses brokers more efficiently.
As Kafka clusters evolve, some brokers may become overloaded while others remain underutilized. Cruise Control addresses this imbalance by modeling resource utilization at the replica level—including, CPU, disk, network load—and generating optimization proposals (which you can approve or reject) for balanced partition assignments based on configurable optimization goals.
Optimization proposals are configured and generated using a KafkaRebalance resource. You can configure the resource using an annotation so that optimization proposals are approved automatically or manually.
Streams for Apache Kafka provides example configuration files for Cruise Control.
21.1. Cruise Control components and features 링크 복사링크가 클립보드에 복사되었습니다!
Cruise Control comprises four main components:
- Load Monitor
- Load Monitor collects the metrics and analyzes cluster workload data.
- Analyzer
- Analyzer generates optimization proposals based on collected data and configured goals.
- Anomaly Detector
- Anomaly Detector identifies and reports irregularities in cluster behavior.
- Executor
- Executor applies approved optimization proposals to the cluster.
- REST API
Cruise Control provides a REST API for client interactions, which Streams for Apache Kafka uses to support these features:
- Generating optimization proposals from optimization goals
- Rebalancing a Kafka cluster based on an optimization proposal
- Changing topic replication factor
- Reassigning partitions between JBOD disks
Other Cruise Control features are not currently supported, including self healing, notifications, and write-your-own goals.
21.1.1. Optimization goals 링크 복사링크가 클립보드에 복사되었습니다!
Optimization goals define objectives for rebalancing, such as distributing topic replicas evenly across brokers.
They are categorized as follows:
- Supported goals are a list of goals supported by the Cruise Control instance that can be used in its operations. By default, this list includes all goals included with Cruise Control. For a goal to be used in other categories, such as default or hard goals, it must first be listed in supported goals. To prevent a goal’s usage, remove it from this list.
- Hard goals are preset and must be satisfied for a proposal to succeed.
- Soft goals are preset goals with objectives that are prioritized during optimization as much as possible, without preventing a proposal from being created if all hard goals are satisfied.
- Default goals refer to the goals used by default when generating proposals. They match the supported goals unless specifically set by the user.
- Proposal-specific goals are a subset of supported goals configured for specific proposals.
Configure optimization goals in the Kafka and KafkaRebalance custom resources.
Kafkaresource for supported, hard, and default goals.-
Supported goals:
Kafka.spec.cruiseControl.config.goals -
Hard goals:
Kafka.spec.cruiseControl.config.hard.goals -
Default goals:
Kafka.spec.cruiseControl.config.default.goals
-
Supported goals:
KafkaRebalanceresource for proposal-specific goals.-
Proposal-specific goals:
KafkaRebalance.spec.goals
-
Proposal-specific goals:
21.1.1.1. Supported goals 링크 복사링크가 클립보드에 복사되었습니다!
Supported goals are predefined and available to use for generating Cruise Control optimization proposals. Goals not listed as supported goals cannot be used in Cruise Control operations. Some supported goals are preset as hard goals.
Configure supported goals in Kafka.spec.cruiseControl.config.goals:
-
To accept inherited supported goals, omit the
goalsproperty. -
To modify supported goals, specify the goals in descending priority order in the
goalsproperty.
21.1.1.2. Hard and soft goals 링크 복사링크가 클립보드에 복사되었습니다!
Hard goals must be satisfied for optimization proposals to be generated. Soft goals are best-effort objectives that Cruise Control tries to meet after all hard goals are satisfied. The classification of hard and soft goals is fixed in Cruise Control code and cannot be changed.
Cruise Control first prioritizes satisfying hard goals, and then addresses soft goals in the order they are listed. A proposal meeting all hard goals is valid, even if it violates some soft goals.
For example, a soft goal might be to evenly distribute a topic’s replicas. Cruise Control continues to generate an optimization proposal even if the soft goal isn’t completely satisfied.
Configure hard goals in your Cruise Control deployment using Kafka.spec.cruiseControl.config.hard.goals:
-
To enforce all hard goals, omit the
hard.goalsproperty. -
To specify hard goals, list them in
hard.goals. -
To exclude a hard goal, ensure it’s not in either
default.goalsorhard.goals.
Increasing the number of configured hard goals will reduce the likelihood of Cruise Control generating optimization proposals.
21.1.1.3. Default goals 링크 복사링크가 클립보드에 복사되었습니다!
Cruise Control uses default goals to generate an optimization proposal.
If default.goals is not specified in the Cruise Control deployment configuration, Streams for Apache Kafka configures default.goals to the list of supported goals specified in goals.
The optimization proposal based on this supported goals list is then generated and cached.
Configure default goals in Kafka.spec.cruiseControl.config.default.goals:
-
To use supported goals as default, omit the
default.goalsproperty. -
To modify default goals, specify a subset of supported goals in the
default.goalsproperty.
You can adjust the priority order in the default goals configuration.
21.1.1.4. Proposal-specific goals 링크 복사링크가 클립보드에 복사되었습니다!
Proposal-specific optimization goals support the creation of optimization proposals based on a specific list of goals. If proposal-specific goals are not set in the KafkaRebalance resource, then default goals are used
Configure proposal-specific goals in KafkaRebalance.spec.goals, specifying a subset of supported optimization goals for customization.
For example, you can optimize topic leader replica distribution across the Kafka cluster without considering disk capacity or utilization by defining a single proposal-specific goal.
21.1.1.5. Goals order of priority 링크 복사링크가 클립보드에 복사되었습니다!
Unless you change the Cruise Control deployment configuration, Streams for Apache Kafka inherits goals from Cruise Control, in descending priority order.
The following list shows supported goals inherited by Streams for Apache Kafka from Cruise Control in descending priority order. Goals labeled as hard are mandatory constraints that must be satisfied for optimization proposals.
-
RackAwareGoal(hard) -
MinTopicLeadersPerBrokerGoal(hard) -
ReplicaCapacityGoal(hard) -
DiskCapacityGoal(hard) -
NetworkInboundCapacityGoal(hard) -
NetworkOutboundCapacityGoal(hard) -
CpuCapacityGoal(hard) -
ReplicaDistributionGoal -
PotentialNwOutGoal -
DiskUsageDistributionGoal -
NetworkInboundUsageDistributionGoal -
NetworkOutboundUsageDistributionGoal -
CpuUsageDistributionGoal -
TopicReplicaDistributionGoal -
LeaderReplicaDistributionGoal -
LeaderBytesInDistributionGoal -
PreferredLeaderElectionGoal -
IntraBrokerDiskCapacityGoal(hard) -
IntraBrokerDiskUsageDistributionGoal
Resource distribution goals are subject to capacity limits on broker resources.
For more information on each optimization goal, see Goals in the Cruise Control Wiki.
"Write your own" goals and Kafka assigner goals are not supported.
Example Kafka configuration for default and hard goals
Ensure that the supported goals, default.goals, and (unless skipHardGoalCheck is set to true) proposal-specific spec.goals include all hard goals specified in hard.goals to avoid errors when generating optimization proposals. Hard goals must be included as a subset in the supported, default, and proposal-specific goals.
Example KafkaRebalance configuration for proposal-specific goals
21.1.1.6. Skipping hard goal checks 링크 복사링크가 클립보드에 복사되었습니다!
If skipHardGoalCheck: true is specified in the KafkaRebalance custom resource, Cruise Control does not verify that the proposal-specific goals include all the configured hard goals. This allows for more flexibility in generating optimization proposals, but may lead to proposals that do not satisfy all hard goals.
However, any hard goals included in the proposal-specific goals will still be treated as hard goals by Cruise Control, even with skipHardGoalCheck: true.
21.1.2. Optimization proposals 링크 복사링크가 클립보드에 복사되었습니다!
Optimization proposals are summaries of proposed changes based on the defined optimization goals, assessed in a specific order of priority. You can approve or reject proposals and rerun them with adjusted goals if needed.
With Cruise Control deployed for use in Streams for Apache Kafka, the process to generate and approve an optimization proposal is as follows:
-
Create a
KafkaRebalanceresource specifying optimization goals and any specific configurations. This resource triggers Cruise Control to initiate the optimization proposal generation process. -
A Cruise Control Metrics Reporter runs in every Kafka broker, collecting raw metrics and publishing them to a dedicated Kafka topic (
strimzi.cruisecontrol.metrics). Metrics for brokers, topics, and partitions are aggregated, sampled, and stored in other topics automatically created when Cruise Control is deployed. - Load Monitor collects, processes, and stores the metrics as a workload model--including CPU, disk, and network utilization data—which is used by the Analyzer and Anomaly Detector.
- Anomaly Detector continuously monitors the health and performance of the Kafka cluster, checking for things like broker failures or disk capacity issues, that could impact cluster stability.
-
Analyzer creates optimization proposals based on the workload model from the Load Monitor. Based on configured goals and capacities, it generates an optimization proposal for balancing partitions across brokers. Through the REST API, a summary of the proposal is reflected in the status of the
KafkaRebalanceresource. - The optimization proposal is approved or rejected (manually or automatically) based on its alignment with cluster management goals.
- If approved, the Executor applies the optimization proposal to rebalance the Kafka cluster. This involves reassigning partitions and redistributing workload across brokers according to the approved proposal.
Figure 21.1. Cruise Control optimization process
Optimization proposals comprise a list of partition reassignment mappings. When you approve a proposal, the Cruise Control server applies these partition reassignments to the Kafka cluster.
A partition reassignment consists of either of the following types of operations:
Partition movement: Involves transferring the partition replica and its data to a new location. Partition movements can take one of two forms:
- Inter-broker movement: The partition replica is moved to a log directory on a different broker.
- Intra-broker movement: The partition replica is moved to a different log directory on the same broker.
- Leadership movement: Involves switching the leader of the partition’s replicas.
Cruise Control issues partition reassignments to the Kafka cluster in batches. The performance of the cluster during the rebalance is affected by the number and magnitude of each type of movement contained in each batch.
21.1.2.1. Rebalancing modes 링크 복사링크가 클립보드에 복사되었습니다!
Proposals for rebalances can be generated in four modes, which are specified using the spec.mode property of the KafkaRebalance custom resource.
fullmode-
The
fullmode runs a full rebalance by moving replicas across all the brokers in the cluster. This is the default mode if thespec.modeproperty is not defined in theKafkaRebalancecustom resource. add-brokersmode-
The
add-brokersmode is used after scaling up a Kafka cluster by adding one or more brokers. Normally, after scaling up a Kafka cluster, new brokers are used to host only the partitions of newly created topics. If no new topics are created, the newly added brokers are not used and the existing brokers remain under the same load. By using theadd-brokersmode immediately after adding brokers to the cluster, the rebalancing operation moves replicas from existing brokers to the newly added brokers. You specify the new brokers as a list using thespec.brokersproperty of theKafkaRebalancecustom resource. remove-brokersmode-
The
remove-brokersmode is used before scaling down a Kafka cluster by removing one or more brokers. Theremove-brokersmode moves replicas off the brokers that are going to be removed. When these brokers are not hosting replicas anymore, you can safely run the scaling down operation. You specify the brokers you’re removing as a list in thespec.brokersproperty in theKafkaRebalancecustom resource. remove-disksmode-
The
remove-disksmode is used specifically to reassign partitions between JBOD disks used for storage on the same broker. You specify a list of broker IDs with corresponding volume IDs for partition reassignment.
Brokers are shut down even if they host replicas when checks are skipped on scale-down operations.
In general, use the full rebalance mode to rebalance a Kafka cluster by spreading the load across brokers. Use the add-brokers and remove-brokers modes only if you want to scale your cluster up or down and rebalance the replicas accordingly.
The procedure to run a rebalance is actually the same across the three different modes. The only difference is with specifying a mode through the spec.mode property and, if needed, listing brokers that have been added or will be removed through the spec.brokers property.
21.1.2.2. The results of an optimization proposal 링크 복사링크가 클립보드에 복사되었습니다!
When an optimization proposal is generated, a summary and broker load is returned.
- Summary
-
The summary is contained in the
KafkaRebalanceresource. The summary provides an overview of the proposed cluster rebalance and indicates the scale of the changes involved. A summary of a successfully generated optimization proposal is contained in theStatus.optimizationResultproperty of theKafkaRebalanceresource. The information provided is a summary of the full optimization proposal. - Broker load
- The broker load is stored in a ConfigMap that contains data as a JSON string. The broker load shows before and after values for the proposed rebalance, so you can see the impact on each of the brokers in the cluster.
21.1.2.3. Manually approving or rejecting an optimization proposal 링크 복사링크가 클립보드에 복사되었습니다!
An optimization proposal summary shows the proposed scope of changes.
You can use the name of the KafkaRebalance resource to return a summary from the command line.
Returning an optimization proposal summary
oc describe kafkarebalance <kafka_rebalance_resource_name> -n <namespace>
oc describe kafkarebalance <kafka_rebalance_resource_name> -n <namespace>
You can also use the jq command line JSON parser tool.
Returning an optimization proposal result using jq
oc get kafkarebalance <kafka_rebalance_resource_name> -n <namespace> -o json | jq '.status.optimizationResult'
oc get kafkarebalance <kafka_rebalance_resource_name> -n <namespace> -o json | jq '.status.optimizationResult'
Use the summary to decide whether to approve or reject an optimization proposal.
- Approving an optimization proposal
-
You approve the optimization proposal by setting the
strimzi.io/rebalanceannotation of theKafkaRebalanceresource toapprove. Cruise Control applies the proposal to the Kafka cluster and starts a cluster rebalance operation. - Rejecting an optimization proposal
-
If you choose not to approve an optimization proposal, you can change the optimization goals or update any of the rebalance performance tuning options, and then generate another proposal. You can generate a new optimization proposal for a
KafkaRebalanceresource by setting thestrimzi.io/rebalanceannotation torefresh.
Use optimization proposals to assess the movements required for a rebalance. For example, a summary describes inter-broker and intra-broker movements. Inter-broker rebalancing moves data between separate brokers. Intra-broker rebalancing moves data between disks on the same broker when you are using a JBOD storage configuration. Such information can be useful even if you don’t go ahead and approve the proposal.
You might reject an optimization proposal, or delay its approval, because of the additional load on a Kafka cluster when rebalancing. If the proposal is delayed for too long, the cluster load may change significantly, so it may be better to request a new proposal.
In the following example, the proposal suggests the rebalancing of data between separate brokers. The rebalance involves the movement of 55 partition replicas, totaling 12MB of data, across the brokers. The proposal will also move 24 partition leaders to different brokers. This requires a change to the cluster metadata, which has a low impact on performance.
The balancedness scores are measurements of the overall balance of the Kafka cluster before and after the optimization proposal is approved. A balancedness score is based on optimization goals. If all goals are satisfied, the score is 100. The score is reduced for each goal that will not be met. Compare the balancedness scores to see whether the Kafka cluster is less balanced than it could be following a rebalance.
Example optimization proposal summary
Though the inter-broker movement of partition replicas has a high impact on performance, the total amount of data is not large. If the total data was much larger, you could reject the proposal, or time when to approve the rebalance to limit the impact on the performance of the Kafka cluster.
Rebalance performance tuning options can help reduce the impact of data movement. If you can extend the rebalance period, you can divide the rebalance into smaller batches. Fewer data movements at a single time reduces the load on the cluster.
21.1.2.4. Optimization proposal summary properties 링크 복사링크가 클립보드에 복사되었습니다!
The following table explains the properties contained in the optimization proposal’s summary.
| JSON property | Description |
|---|---|
|
| The total number of partition replicas that will be transferred between the disks of the cluster’s brokers.
Performance impact during rebalance operation: Relatively high, but lower than |
|
| Not yet supported. An empty list is returned. |
|
| The number of partition replicas that will be moved between separate brokers. Performance impact during rebalance operation: Relatively high. |
|
| A measurement of the overall balancedness of a Kafka Cluster, before and after the optimization proposal was generated.
The score is calculated by subtracting the sum of the
The |
|
|
The sum of the size of each partition replica that will be moved between disks on the same broker (see also
Performance impact during rebalance operation: Variable. The larger the number, the longer the cluster rebalance will take to complete. Moving a large amount of data between disks on the same broker has less impact than between separate brokers (see |
|
| The number of metrics windows upon which the optimization proposal is based. |
|
|
The sum of the size of each partition replica that will be moved to a separate broker (see also Performance impact during rebalance operation: Variable. The larger the number, the longer the cluster rebalance will take to complete. |
|
|
The percentage of partitions in the Kafka cluster covered by the optimization proposal. Affected by the number of |
|
|
If you specified a regular expression in the |
|
| The number of partitions whose leaders will be switched to different replicas. This involves a change to ZooKeeper configuration. Performance impact during rebalance operation: Relatively low. |
|
| Not yet supported. An empty list is returned. |
21.1.2.5. Automatically approving an optimization proposal 링크 복사링크가 클립보드에 복사되었습니다!
To save time, you can automate the process of approving optimization proposals. With automation, when you generate an optimization proposal it goes straight into a cluster rebalance.
To enable the optimization proposal auto-approval mechanism, create the KafkaRebalance resource with the strimzi.io/rebalance-auto-approval annotation set to true. If the annotation is not set or set to false, the optimization proposal requires manual approval.
Example rebalance request with auto-approval mechanism enabled
You can still check the status when automatically approving an optimization proposal. The status of the KafkaRebalance resource moves to Ready when the rebalance is complete.
21.1.2.6. Comparing broker load data 링크 복사링크가 클립보드에 복사되었습니다!
Broker load data provides insights into current and anticipated usage of resources following a rebalance. The data is stored in a ConfigMap (with the same name as the KafkaRebalance resource) as a JSON formatted string
When a Kafka rebalance proposal reaches the ProposalReady state, Streams for Apache Kafka creates a ConfigMap (named after the KafkaRebalance custom resource) containing a JSON string of broker metrics generated from Cruise Control. Each broker has a set of key metrics represented by three values:
- The current metric value before the optimization proposal is applied
- The expected metric value after applying the proposal
- The difference between the two values (after minus before)
This ConfigMap remains accessible even after the rebalance completes.
To view this data from the command line, use the ConfigMap name.
Returning ConfigMap data
oc describe configmaps <my_rebalance_configmap_name> -n <namespace>
oc describe configmaps <my_rebalance_configmap_name> -n <namespace>
You can also use the jq command line JSON parser tool to extract the JSON string.
Extracting the JSON string from the ConfigMap using jq
oc get configmaps <my_rebalance_configmap_name> -o json | jq '.["data"]["brokerLoad.json"]|fromjson|.'
oc get configmaps <my_rebalance_configmap_name> -o json | jq '.["data"]["brokerLoad.json"]|fromjson|.'
| JSON property | Description |
|---|---|
|
| The number of replicas on this broker that are partition leaders. |
|
| The number of replicas on this broker. |
|
| The CPU utilization as a percentage of the defined capacity. |
|
| The disk utilization as a percentage of the defined capacity. |
|
| The absolute disk usage in MB. |
|
| The total network output rate for the broker. |
|
| The network input rate for all partition leader replicas on this broker. |
|
| The network input rate for all follower replicas on this broker. |
|
| The hypothetical maximum network output rate that would be realized if this broker became the leader of all the replicas it currently hosts. |
21.1.2.7. Adjusting the cached proposal refresh rate 링크 복사링크가 클립보드에 복사되었습니다!
Cruise Control maintains a cached optimization proposal based on the configured default optimization goals. This proposal is generated from the workload model and updated every 15 minutes to reflect the current state of the Kafka cluster. When you generate an optimization proposal using the default goals, Cruise Control returns the latest cached version.
For clusters with rapidly changing workloads, you may want to shorten the refresh interval to ensure the optimization proposal reflects the most recent state. However, reducing the interval increases the load on the Cruise Control server. To adjust the refresh rate, modify the proposal.expiration.ms setting in the Cruise Control deployment configuration.
21.1.3. Tuning options for rebalances 링크 복사링크가 클립보드에 복사되었습니다!
Configuration options allow you to fine-tune cluster rebalance performance. These settings control the movement of partition replicas and leadership, as well as the bandwidth allocated for rebalances.
21.1.3.1. Selecting replica movement strategies 링크 복사링크가 클립보드에 복사되었습니다!
Cluster rebalance performance is also influenced by the replica movement strategy that is applied to the batches of partition reassignment commands. By default, Cruise Control uses the BaseReplicaMovementStrategy, which applies the reassignments in the order they were generated. However, this strategy could lead to the delay of other partition reassignments if large partition reassignments are generated then ordered first.
Cruise Control provides four alternative replica movement strategies that can be applied to optimization proposals:
-
PrioritizeSmallReplicaMovementStrategy: Reassign smaller partitions first. -
PrioritizeLargeReplicaMovementStrategy: Reassign larger partitions first. -
PostponeUrpReplicaMovementStrategy: Prioritize partitions without out-of-sync replicas. -
PrioritizeMinIsrWithOfflineReplicasStrategy: Prioritize reassignments for partitions at or below their minimum in-sync replicas (MinISR) with offline replicas.
SetcruiseControl.config.concurrency.adjuster.min.isr.check.enabledtotruein theKafkaresource to enable this strategy.
These strategies can be configured as a sequence. The first strategy attempts to compare two partition reassignments using its internal logic. If the reassignments are equivalent, then it passes them to the next strategy in the sequence to decide the order, and so on.
21.1.3.2. Intra-broker disk balancing 링크 복사링크가 클립보드에 복사되었습니다!
Intra-broker balancing shifts data between disks on the same broker, useful for deployments with JBOD storage and multiple disks. This type of balancing incurs less network overhead than inter-broker balancing.
If you are using JBOD storage with a single disk, intra-broker disk balancing will result in a proposal with 0 partition movements since there are no disks to balance.
To enable intra-broker balancing, set rebalanceDisk to true in KafkaRebalance.spec. When this is enabled, do not specify a goals field, as Cruise Control will automatically configure intra-broker goals and disregard inter-broker goals. Cruise Control does not perform inter-broker and intra-broker balancing at the same time.
21.1.3.3. Rebalance tuning 링크 복사링크가 클립보드에 복사되었습니다!
You can set the following rebalance tuning options when configuring Cruise Control or individual rebalances:
-
Set Cruise Control server configurations in
Kafka.spec.cruiseControl.configin theKafkaresource. -
Set proposal-specific configurations in
KafkaRebalance.specin theKafkaRebalanceresource.
| Cruise Control properties | KafkaRebalance properties | Default | Description |
|---|---|---|---|
|
|
| 5 | The maximum number of inter-broker partition movements in each partition reassignment batch |
|
|
| 2 | The maximum number of intra-broker partition movements in each partition reassignment batch |
|
|
| 1000 | The maximum number of partition leadership changes in each partition reassignment batch |
|
|
| Null (no limit) | The bandwidth (in bytes per second) to assign to partition reassignment |
|
|
|
|
The list of strategies (in priority order) used to determine the order in which partition reassignment commands are executed for generated proposals. For the server setting, use a comma separated string with the fully qualified names of the strategy class (add |
| - |
| false | Enables intra-broker disk balancing, which balances disk space utilization between disks on the same broker. Only applies to Kafka deployments that use JBOD storage with multiple disks. |
Changing the default settings affects the length of time that the rebalance takes to complete, as well as the load placed on the Kafka cluster during the rebalance. Using lower values reduces the load but increases the amount of time taken, and vice versa.
21.2. Deploying Cruise Control with Kafka 링크 복사링크가 클립보드에 복사되었습니다!
Configure a Kafka resource to deploy Cruise Control alongside a Kafka cluster. You can use the cruiseControl properties of the Kafka resource to configure the deployment. Deploy one instance of Cruise Control per Kafka cluster.
Use goals configuration in the Cruise Control config to specify optimization goals for generating optimization proposals. You can use brokerCapacity to change the default capacity limits for goals related to resource distribution. If brokers are running on nodes with heterogeneous network resources, you can use overrides to set network capacity limits for each broker.
If an empty object ({}) is used for the cruiseControl configuration, all properties use their default values.
Streams for Apache Kafka provides example configuration files, which include Kafka custom resources with Cruise Control configuration. For more information on the configuration options for Cruise Control, see the Streams for Apache Kafka Custom Resource API Reference.
Prerequisites
Procedure
Edit the
cruiseControlproperty for theKafkaresource.The properties you can configure are shown in this example configuration:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Capacity limits for broker resources.
- 2
- Overrides set network capacity limits for specific brokers when running on nodes with heterogeneous network resources.
- 3
- Cruise Control configuration. Standard Cruise Control configuration may be provided, restricted to those properties not managed directly by Streams for Apache Kafka.
- 4
- Optimization goals configuration, which can include configuration for default optimization goals (
default.goals), supported optimization goals (goals), and hard goals (hard.goals). - 5
- CORS enabled and configured for read-only access to the Cruise Control API.
- 6
- Requests for reservation of supported resources, currently
cpuandmemory, and limits to specify the maximum resources that can be consumed. - 7
- Cruise Control loggers and log levels added directly (
inline) or indirectly (external) through a ConfigMap. A custom Log4j configuration must be placed under thelog4j.propertieskey in the ConfigMap. Cruise Control has a single logger namedrootLogger.level. You can set the log level to INFO, ERROR, WARN, TRACE, DEBUG, FATAL or OFF. - 8
- Template customization. Here a pod is scheduled with additional security attributes.
- 9
- Healthchecks to know when to restart a container (liveness) and when a container can accept traffic (readiness).
- 10
- Prometheus metrics enabled. In this example, metrics are configured for the Prometheus JMX Exporter (the default metrics exporter).
Create or update the resource:
oc apply -f <kafka_configuration_file>
oc apply -f <kafka_configuration_file>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check the status of the deployment:
oc get deployments -n <my_cluster_operator_namespace>
oc get deployments -n <my_cluster_operator_namespace>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Output shows the deployment name and readiness
NAME READY UP-TO-DATE AVAILABLE my-cluster-cruise-control 1/1 1 1
NAME READY UP-TO-DATE AVAILABLE my-cluster-cruise-control 1/1 1 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow my-clusteris the name of the Kafka cluster.READYshows the number of replicas that are ready/expected. The deployment is successful when theAVAILABLEoutput shows1.
21.2.1. Auto-created Cruise Control topics 링크 복사링크가 클립보드에 복사되었습니다!
The following table shows the three topics that are automatically created when Cruise Control is deployed. These topics are required for Cruise Control to work properly and must not be deleted or changed. You can change the name of the topic using the specified configuration option.
| Auto-created topic configuration | Default topic name | Created by | Function |
|---|---|---|---|
|
|
| Streams for Apache Kafka Metrics Reporter | Stores the raw metrics from the Metrics Reporter in each Kafka broker. |
|
|
| Cruise Control | Stores the derived metrics for each partition. These are created by the Metric Sample Aggregator. |
|
|
| Cruise Control | Stores the metrics samples used to create the Cluster Workload Model. |
To prevent the removal of records that are needed by Cruise Control, log compaction is disabled in the auto-created topics.
If the names of the auto-created topics are changed in a Kafka cluster that already has Cruise Control enabled, the old topics will not be deleted and should be manually removed.
What to do next
After configuring and deploying Cruise Control, you can generate optimization proposals.
21.3. Generating optimization proposals 링크 복사링크가 클립보드에 복사되었습니다!
When you create or update a KafkaRebalance resource, Cruise Control generates an optimization proposal for the Kafka cluster based on a set of optimization goals. Analyze the information in the optimization proposal and decide whether to approve it. You can use the results of the optimization proposal to rebalance your Kafka cluster.
This procedure covers using the following modes for generating optimization proposals related to rebalances:
-
full(default) -
add-brokers -
remove-brokers
The mode you use depends on whether you are rebalancing across all the brokers already running in the Kafka cluster; or you want to rebalance after scaling up or before scaling down your Kafka cluster. For more information, see Rebalancing modes with broker scaling.
Prerequisites
- You have deployed Cruise Control to your Streams for Apache Kafka cluster.
- You have configured optimization goals and, optionally, capacity limits on broker resources.
For more information on configuring Cruise Control, see Section 21.2, “Deploying Cruise Control with Kafka”.
Procedure
Create a
KafkaRebalanceresource and specify the appropriate mode.fullmode (default)To use the default optimization goals defined in the
Kafkaresource, leave thespecproperty empty. Cruise Control rebalances a Kafka cluster infullmode by default.Example configuration with full rebalancing by default
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can also run a full rebalance by specifying the
fullmode through thespec.modeproperty.Example configuration specifying
fullmodeCopy to Clipboard Copied! Toggle word wrap Toggle overflow add-brokersmodeIf you want to rebalance a Kafka cluster after scaling up, specify the
add-brokersmode.In this mode, existing replicas are moved to the newly added brokers. You need to specify the brokers as a list.
Example configuration specifying
add-brokersmodeCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- List of newly added brokers added by the scale up operation. This property is mandatory.
remove-brokersmodeIf you want to rebalance a Kafka cluster before scaling down, specify the
remove-brokersmode.In this mode, replicas are moved off the brokers that are going to be removed. You need to specify the brokers that are being removed as a list.
Example configuration specifying
remove-brokersmodeCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- List of brokers to be removed by the scale down operation. This property is mandatory.
NoteThe following steps and the steps to approve or stop a rebalance are the same regardless of the rebalance mode you are using.
To configure proposal-specific optimization goals instead of using the default goals, add the
goalsproperty and enter one or more goals.In the following example, rack awareness and replica capacity are configured as proposal-specific optimization goals:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To ignore the configured hard goals, add the
skipHardGoalCheck: trueproperty:Copy to Clipboard Copied! Toggle word wrap Toggle overflow (Optional) To approve the optimization proposal automatically, set the
strimzi.io/rebalance-auto-approvalannotation totrue:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create or update the resource:
oc apply -f <kafka_rebalance_configuration_file>
oc apply -f <kafka_rebalance_configuration_file>Copy to Clipboard Copied! Toggle word wrap Toggle overflow The Cluster Operator requests the optimization proposal from Cruise Control. This might take a few minutes depending on the size of the Kafka cluster.
If you used the automatic approval mechanism, wait for the status of the optimization proposal to change to
Ready. If you haven’t enabled the automatic approval mechanism, wait for the status of the optimization proposal to change toProposalReady:oc get kafkarebalance -o wide -w -n <namespace>
oc get kafkarebalance -o wide -w -n <namespace>Copy to Clipboard Copied! Toggle word wrap Toggle overflow PendingProposal-
A
PendingProposalstatus means the rebalance operator is polling the Cruise Control API to check if the optimization proposal is ready. ProposalReady-
A
ProposalReadystatus means the optimization proposal is ready for review and approval.
When the status changes to
ProposalReady, the optimization proposal is ready to approve.Review the optimization proposal.
The optimization proposal is contained in the
Status.Optimization Resultproperty of theKafkaRebalanceresource.oc describe kafkarebalance <kafka_rebalance_resource_name>
oc describe kafkarebalance <kafka_rebalance_resource_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example optimization proposal
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The properties in the
Optimization Resultsection describe the pending cluster rebalance operation. For descriptions of each property, see Contents of optimization proposals.
Insufficient CPU capacity
If a Kafka cluster is overloaded in terms of CPU utilization, you might see an insufficient CPU capacity error in the KafkaRebalance status. It’s worth noting that this utilization value is unaffected by the excludedTopics configuration. Although optimization proposals will not reassign replicas of excluded topics, their load is still considered in the utilization calculation.
Example CPU utilization error
com.linkedin.kafka.cruisecontrol.exception.OptimizationFailureException: [CpuCapacityGoal] Insufficient capacity for cpu (Utilization 615.21, Allowed Capacity 420.00, Threshold: 0.70). Add at least 3 brokers with the same cpu capacity (100.00) as broker-0. Add at least 3 brokers with the same cpu capacity (100.00) as broker-0.
com.linkedin.kafka.cruisecontrol.exception.OptimizationFailureException:
[CpuCapacityGoal] Insufficient capacity for cpu (Utilization 615.21, Allowed Capacity 420.00, Threshold: 0.70). Add at least 3 brokers with the same cpu capacity (100.00) as broker-0. Add at least 3 brokers with the same cpu capacity (100.00) as broker-0.
The error shows CPU capacity as a percentage rather than the number of CPU cores. For this reason, it does not directly map to the number of CPUs configured in the Kafka custom resource. It is like having a single virtual CPU per broker, which has the cycles of the CPUs configured in Kafka.spec.kafka.resources.limits.cpu. This has no effect on the rebalance behavior, since the ratio between CPU utilization and capacity remains the same.
What to do next
21.4. Approving optimization proposals 링크 복사링크가 클립보드에 복사되었습니다!
You can approve an optimization proposal generated by Cruise Control, if its status is ProposalReady. Cruise Control will then apply the optimization proposal to the Kafka cluster, reassigning partitions to brokers and changing partition leadership.
This is not a dry run. Before you approve an optimization proposal, you must:
- Refresh the proposal in case it has become out of date.
- Carefully review the contents of the proposal.
Prerequisites
- You have generated an optimization proposal from Cruise Control.
-
The
KafkaRebalancecustom resource status isProposalReady.
Procedure
Perform these steps for the optimization proposal that you want to approve.
Unless the optimization proposal is newly generated, check that it is based on current information about the state of the Kafka cluster. To do so, annotate the
KafkaRebalanceresource to refresh the optimization proposal and make sure it uses the latest cluster metrics:oc annotate kafkarebalance <kafka_rebalance_resource_name> strimzi.io/rebalance="refresh"
oc annotate kafkarebalance <kafka_rebalance_resource_name> strimzi.io/rebalance="refresh"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Wait for the status of the optimization proposal to change to
ProposalReady:oc get kafkarebalance -o wide -w -n <namespace>
oc get kafkarebalance -o wide -w -n <namespace>Copy to Clipboard Copied! Toggle word wrap Toggle overflow PendingProposal-
A
PendingProposalstatus means the rebalance operator is polling the Cruise Control API to check if the optimization proposal is ready. ProposalReady-
A
ProposalReadystatus means the optimization proposal is ready for review and approval.
When the status changes to
ProposalReady, the optimization proposal is ready to approve.Annotate the
KafkaRebalanceresource to approve the optimization proposal:oc annotate kafkarebalance <kafka_rebalance_resource_name> strimzi.io/rebalance="approve"
oc annotate kafkarebalance <kafka_rebalance_resource_name> strimzi.io/rebalance="approve"Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The Cluster Operator detects the annotated resource and instructs Cruise Control to rebalance the Kafka cluster.
Wait for the status of the optimization proposal to change to
Ready:oc get kafkarebalance -o wide -w -n <namespace>
oc get kafkarebalance -o wide -w -n <namespace>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Rebalancing-
A
Rebalancingstatus means the rebalancing is in progress. Ready-
A
Readystatus means the rebalance is complete. NotReady-
A
NotReadystatus means an error occurred—see Fixing problems with aKafkaRebalanceresource.
When the status changes to
Ready, the rebalance is complete.To use the same
KafkaRebalancecustom resource to generate another optimization proposal, apply therefreshannotation to the custom resource. This moves the custom resource to thePendingProposalorProposalReadystate. You can then review the optimization proposal and approve it, if desired.
21.5. Stopping rebalances 링크 복사링크가 클립보드에 복사되었습니다!
Once started, a cluster rebalance operation might take some time to complete and affect the overall performance of the Kafka cluster.
If you want to stop a cluster rebalance operation that is in progress, apply the stop annotation to the KafkaRebalance custom resource. This instructs Cruise Control to finish the current batch of partition reassignments and then stop the rebalance. When the rebalance has stopped, completed partition reassignments have already been applied; therefore, the state of the Kafka cluster is different when compared to prior to the start of the rebalance operation. If further rebalancing is required, you should generate a new optimization proposal.
The performance of the Kafka cluster in the intermediate (stopped) state might be worse than in the initial state.
Prerequisites
-
The status of the
KafkaRebalancecustom resource isRebalancing.
Procedure
Annotate the
KafkaRebalanceresource to stop the rebalance:oc annotate kafkarebalance <kafka_rebalance_resource_name> strimzi.io/rebalance="stop"
oc annotate kafkarebalance <kafka_rebalance_resource_name> strimzi.io/rebalance="stop"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check the status of the
KafkaRebalanceresource:oc describe kafkarebalance <kafka_rebalance_resource_name>
oc describe kafkarebalance <kafka_rebalance_resource_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Wait until the status changes to
Stopped.
21.6. Troubleshooting and refreshing rebalances 링크 복사링크가 클립보드에 복사되었습니다!
When creating a KafkaRebalance resource or interacting with Cruise Control, errors are reported in the resource status, along with guidance on how to fix them. In such cases, the resource transitions to the NotReady state.
To continue with a cluster rebalance operation, you must rectify any configuration issues in the KafkaRebalance resource or address any problems with the Cruise Control deployment.
Common issues include the following:
-
Misconfigured parameters in the
KafkaRebalanceresource. -
The
strimzi.io/clusterlabel for specifying the Kafka cluster in theKafkaRebalanceresource is missing. -
The Cruise Control server is not deployed as the
cruiseControlproperty in theKafkaresource is missing. - The Cruise Control server is not reachable.
After fixing any issues, you need to add the refresh annotation to the KafkaRebalance resource. During a “refresh”, a new optimization proposal is requested from the Cruise Control server.
Prerequisites
- You have approved an optimization proposal.
-
The status of the
KafkaRebalancecustom resource for the rebalance operation isNotReady.
Procedure
Get information about the error from the
KafkaRebalancestatus:oc describe kafkarebalance <kafka_rebalance_resource_name>
oc describe kafkarebalance <kafka_rebalance_resource_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Attempt to resolve the issue by annotating the
KafkaRebalanceresource to refresh the proposal:oc annotate kafkarebalance <kafka_rebalance_resource_name> strimzi.io/rebalance="refresh"
oc annotate kafkarebalance <kafka_rebalance_resource_name> strimzi.io/rebalance="refresh"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check the status of the
KafkaRebalanceresource:oc describe kafkarebalance <kafka_rebalance_resource_name>
oc describe kafkarebalance <kafka_rebalance_resource_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Wait until the status changes to
PendingProposal, or directly toProposalReady.