Cruise Control is an open source system for automating Kafka operations, such as monitoring cluster workload, rebalancing a cluster based on predefined constraints, and detecting and fixing anomalies.
It consists of four main components—the Load Monitor, the Analyzer, the Anomaly Detector, and the Executor—and a REST API for client interactions.
Strimzi utilizes the REST API to support the following Cruise Control features:
Cruise Control reduces the time and effort involved in running an efficient and balanced Kafka cluster.
A typical cluster can become unevenly loaded over time.
Partitions that handle large amounts of message traffic might be unevenly distributed across the available brokers.
To rebalance the cluster, administrators must monitor the load on brokers and manually reassign busy partitions to brokers with spare capacity.
Cruise Control automates the cluster rebalancing process.
It constructs a workload model of resource utilization for the cluster—based on CPU, disk, and network load—and generates optimization proposals (that you can approve or reject) for more balanced partition assignments.
A set of configurable optimization goals is used to calculate these proposals.
When you approve an optimization proposal, Cruise Control applies it to your Kafka cluster.
When the cluster rebalancing operation is complete, the broker pods are used more effectively and the Kafka cluster is more evenly balanced.
To rebalance a Kafka cluster, Cruise Control uses optimization goals to generate optimization proposals, which you can approve or reject.
Optimization goals are constraints on workload redistribution and resource utilization across a Kafka cluster.
With a few exceptions, Strimzi supports all the optimization goals developed in the Cruise Control project.
The supported goals, in the default descending order of priority, are as follows:
-
Rack-awareness
-
Replica capacity
-
Capacity: Disk capacity, Network inbound capacity, Network outbound capacity
-
Replica distribution
-
Potential network output
-
Resource distribution: Disk utilization distribution, Network inbound utilization distribution, Network outbound utilization distribution
-
Leader bytes-in rate distribution
-
Topic replica distribution
-
Leader replica distribution
-
Preferred leader election
For more information on each optimization goal, see Goals in the Cruise Control Wiki.
Note
|
CPU goals, intra-broker disk goals, "Write your own" goals, and Kafka assigner goals are not yet supported.
|
Goals configuration in Strimzi custom resources
You configure optimization goals in Kafka
and KafkaRebalance
custom resources. Cruise Control has configurations for hard optimization goals that must be satisfied, as well as master, default, and user-provided optimization goals.
Optimization goals are subject to any capacity limits on broker resources.
The following sections describe each goal configuration in more detail.
Hard goals and soft goals
Hard goals are goals that must be satisfied in optimization proposals.
Goals that are not configured as hard goals are known as soft goals.
You can think of soft goals as best effort goals: they do not need to be satisfied in optimization proposals, but are included in optimization calculations.
An optimization proposal that violates one or more soft goals, but satisfies all hard goals, is valid.
Cruise Control will calculate optimization proposals that satisfy all the hard goals and as many soft goals as possible (in their priority order).
An optimization proposal that does not satisfy all the hard goals is rejected by Cruise Control and not sent to the user for approval.
Note
|
For example, you might have a soft goal to distribute a topic’s replicas evenly across the cluster (the topic replica distribution goal).
Cruise Control will ignore this goal if doing so enables all the configured hard goals to be met.
|
RackAwareGoal; ReplicaCapacityGoal; DiskCapacityGoal; NetworkInboundCapacityGoal; NetworkOutboundCapacityGoal
You configure hard goals in the Cruise Control deployment configuration, by editing the hard.goals
property in Kafka.spec.cruiseControl.config
.
-
To inherit the preset hard goals from Cruise Control, do not specify the hard.goals
property in Kafka.spec.cruiseControl.config
-
To change the preset hard goals, specify the desired goals in the hard.goals
property, using their fully-qualified domain names.
Example Kafka
configuration for hard optimization goals
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
name: my-cluster
spec:
kafka:
# ...
zookeeper:
# ...
entityOperator:
topicOperator: {}
userOperator: {}
cruiseControl:
brokerCapacity:
inboundNetwork: 10000KB/s
outboundNetwork: 10000KB/s
config:
hard.goals: >
com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkInboundCapacityGoal,
com.linkedin.kafka.cruisecontrol.analyzer.goals.NetworkOutboundCapacityGoal
# ...
Increasing the number of configured hard goals will reduce the likelihood of Cruise Control generating valid optimization proposals.
If skipHardGoalCheck: true
is specified in the KafkaRebalance
custom resource, Cruise Control does not check that the list of user-provided optimization goals (in KafkaRebalance.spec.goals
) contains all the configured hard goals (hard.goals
).
Therefore, if some, but not all, of the user-provided optimization goals are in the hard.goals
list, Cruise Control will still treat them as hard goals even if skipHardGoalCheck: true
is specified.
Master optimization goals
The master optimization goals are available to all users.
Goals that are not listed in the master optimization goals are not available for use in Cruise Control operations.
Unless you change the Cruise Control deployment configuration, Strimzi will inherit the following master optimization goals from Cruise Control, in descending priority order:
RackAwareGoal; ReplicaCapacityGoal; DiskCapacityGoal; NetworkInboundCapacityGoal; NetworkOutboundCapacityGoal; ReplicaDistributionGoal; PotentialNwOutGoal; DiskUsageDistributionGoal; NetworkInboundUsageDistributionGoal; NetworkOutboundUsageDistributionGoal; TopicReplicaDistributionGoal; LeaderReplicaDistributionGoal; LeaderBytesInDistributionGoal; PreferredLeaderElectionGoal
To reduce complexity, we recommend that you use the inherited master optimization goals, unless you need to completely exclude one or more goals from use in KafkaRebalance
resources. The priority order of the master optimization goals can be modified, if desired, in the configuration for default optimization goals.
You configure master optimization goals, if necessary, in the Cruise Control deployment configuration: Kafka.spec.cruiseControl.config.goals
-
To accept the inherited master optimization goals, do not specify the goals
property in Kafka.spec.cruiseControl.config
.
-
If you need to modify the inherited master optimization goals, specify a list of goals, in descending priority order, in the goals
configuration option.
Note
|
If you change the inherited master optimization goals, you must ensure that the hard goals, if configured in the hard.goals property in Kafka.spec.cruiseControl.config , are a subset of the master optimization goals that you configured. Otherwise, errors will occur when generating optimization proposals.
|
Default optimization goals
Cruise Control uses the default optimization goals to generate the cached optimization proposal.
For more information about the cached optimization proposal, see Optimization proposals overview.
Unless you specify default.goals
in the Cruise Control deployment configuration, the master optimization goals are used as the default optimization goals.
In this case, the cached optimization proposal is generated using the master optimization goals.
-
To use the master optimization goals as the default goals, do not specify the default.goals
property in Kafka.spec.cruiseControl.config
.
-
To modify the default optimization goals, edit the default.goals
property in Kafka.spec.cruiseControl.config
.
You must use a subset of the master optimization goals.
Example Kafka
configuration for default optimization goals
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
name: my-cluster
spec:
kafka:
# ...
zookeeper:
# ...
entityOperator:
topicOperator: {}
userOperator: {}
cruiseControl:
brokerCapacity:
inboundNetwork: 10000KB/s
outboundNetwork: 10000KB/s
config:
default.goals: >
com.linkedin.kafka.cruisecontrol.analyzer.goals.RackAwareGoal,
com.linkedin.kafka.cruisecontrol.analyzer.goals.ReplicaCapacityGoal,
com.linkedin.kafka.cruisecontrol.analyzer.goals.DiskCapacityGoal
# ...
If no default optimization goals are specified, the cached proposal is generated using the master optimization goals.
User-provided optimization goals
User-provided optimization goals narrow down the configured default goals for a particular optimization proposal.
You can set them, as required, in spec.goals
in the KafkaRebalance
custom resource:
KafkaRebalance.spec.goals
User-provided optimization goals can generate optimization proposals for different scenarios.
For example, you might want to optimize leader replica distribution across the Kafka cluster without considering disk capacity or disk utilization.
So, you create a KafkaRebalance
custom resource containing a single user-provided goal for leader replica distribution.
User-provided optimization goals must:
To ignore the configured hard goals in an optimization proposal, add the skipHardGoalCheck: true
option to the KafkaRebalance
custom resource.
An optimization proposal is a summary of proposed changes that would produce a more balanced Kafka cluster, with partition workloads distributed more evenly among the brokers.
Each optimization proposal is based on the set of optimization goals that was used to generate it, subject to any configured capacity limits on broker resources.
An optimization proposal is contained in the Status.Optimization Result
property of a KafkaRebalance
custom resource.
The information provided is a summary of the full optimization proposal.
Use the summary to decide whether to:
-
Approve the optimization proposal. This instructs Cruise Control to apply the proposal to the Kafka cluster and start a cluster rebalance operation.
-
Reject the optimization proposal. You can change the optimization goals and then generate another proposal.
All optimization proposals are dry runs: you cannot approve a cluster rebalance without first generating an optimization proposal.
There is no limit to the number of optimization proposals that can be generated.
Cached optimization proposal
Cruise Control maintains a cached optimization proposal based on the configured default optimization goals.
Generated from the workload model, the cached optimization proposal is updated every 15 minutes to reflect the current state of the Kafka cluster.
If you generate an optimization proposal using the default optimization goals, Cruise Control returns the most recent cached proposal.
To change the cached optimization proposal refresh interval, edit the proposal.expiration.ms
setting in the Cruise Control deployment configuration.
Consider a shorter interval for fast changing clusters, although this increases the load on the Cruise Control server.
Contents of optimization proposals
The following table explains the properties contained in an optimization proposal:
JSON property |
Description |
numIntraBrokerReplicaMovements
|
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 numReplicaMovements . |
excludedBrokersForLeadership
|
Not yet supported. An empty list is returned. |
numReplicaMovements
|
The number of partition replicas that will be moved between separate brokers.
Performance impact during rebalance operation: Relatively high. |
onDemandBalancednessScoreBefore, onDemandBalancednessScoreAfter
|
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 BalancednessScore of each violated soft goal from 100. Cruise Control assigns a BalancednessScore to every optimization goal based on several factors, including priority—the goal’s position in the list of default.goals or user-provided goals.
The Before score is based on the current configuration of the Kafka cluster.
The After score is based on the generated optimization proposal. |
intraBrokerDataToMoveMB
|
The sum of the size of each partition replica that will be moved between disks on the same broker (see also numIntraBrokerReplicaMovements ).
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 dataToMoveMB ). |
recentWindows
|
The number of metrics windows upon which the optimization proposal is based. |
dataToMoveMB
|
The sum of the size of each partition replica that will be moved to a separate broker (see also numReplicaMovements ).
Performance impact during rebalance operation: Variable. The larger the number, the longer the cluster rebalance will take to complete. |
monitoredPartitionsPercentage
|
The percentage of partitions in the Kafka cluster covered by the optimization proposal. Affected by the number of excludedTopics . |
excludedTopics
|
If you specified a regular expression in the spec.excludedTopicsRegex property in the KafkaRebalance resource, all topic names matching that expression are listed here.
These topics are excluded from the calculation of partition replica/leader movements in the optimization proposal. |
numLeaderMovements
|
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. |
excludedBrokersForReplicaMove
|
Not yet supported. An empty list is returned. |
When an optimization proposal is approved, the partition reassignment commands that comprise the proposal are applied to the Kafka cluster by the Cruise Control server.
These commands consist of two 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:
-
Leadership movement: This involves switching the leader of the partition’s replicas.
Cruise Control batches up these reassignment commands and issues them to the Kafka cluster.
The performance of the cluster during the rebalance is affected by the number of each type of movement contained in each batch.
Cruise Control provides several configuration options for tuning a cluster rebalance for optimal performance.
-
The Cruise Control server setting can be set in the Kafka custom resource under Kafka.spec.kafka.spec.cruiseControl.spec
.
-
The individual rebalance performance configurations can be set under KafkaRebalance.spec
.
The relevant configurations are summarised below:
Server Configuration |
KafkaRebalance Configuration |
Description |
Default Value |
num.concurrent.partition.movements.per.broker
|
concurrentPartitionMovementsPerBroker
|
The maximum number of inter-broker partition movements in each partition reassignment batch |
5 |
num.concurrent.intra.broker.partition.movements
|
concurrentIntraBrokerPartitionMovements
|
The maximum number of intra-broker partition movements in each partition reassignment batch |
2 |
num.concurrent.leader.movements
|
concurrentLeaderMovements
|
The maximum number of partition leadership changes in each partition reassignment batch |
1000 |
default.replication.throttle
|
replicationThrottle
|
The bandwidth (in bytes per second) to be assigned to the reassigning of partitions |
No Limit |
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.
The config
property in Kafka.spec.cruiseControl
contains configuration options as keys with values as one of the following JSON types:
Note
|
Strings that look like JSON or YAML will need to be explicitly quoted.
|
You can specify and configure all the options listed in the "Configurations" section of the Cruise Control documentation, apart from those managed directly by Strimzi.
Specifically, you cannot modify configuration options with keys equal to or starting with one of the following strings:
-
bootstrap.servers
-
zookeeper.
-
ssl.
-
security.
-
failed.brokers.zk.path
-
webserver.http.port
-
webserver.http.address
-
webserver.api.urlprefix
-
metric.reporter.sampler.bootstrap.servers
-
metric.reporter.topic
-
metric.reporter.topic.pattern
-
partition.metric.sample.store.topic
-
broker.metric.sample.store.topic
-
capacity.config.file
-
skip.sample.store.topic.rack.awareness.check
-
cruise.control.metrics.topic
-
sasl.
If restricted options are specified, they are ignored and a warning message is printed to the Cluster Operator log file.
All the supported options are passed to Cruise Control.
An example Cruise Control configuration
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
name: my-cluster
spec:
# ...
cruiseControl:
# ...
config:
default.goals: >
com.linkedin.kafka.cruisecontrol.analyzer.goals.RackAwareGoal,
com.linkedin.kafka.cruisecontrol.analyzer.goals.ReplicaCapacityGoal
cpu.balance.threshold: 1.1
metadata.max.age.ms: 300000
send.buffer.bytes: 131072
# ...
Capacity configuration
Cruise Control uses capacity limits to determine if certain resource-based optimization goals are being broken.
You specify capacity limits for Kafka broker resources in the brokerCapacity
property in Kafka.spec.cruiseControl
.
Capacity limits can be set for the following broker resources using the standard Kubernetes byte units K, M, G and T or their bibyte (power of two) equivalents Ki, Mi, Gi and Ti:
-
disk
- Disk storage per broker (Default: 100000Mi)
-
cpuUtilization
- CPU utilization as a percentage (Default: 100)
-
inboundNetwork
- Inbound network throughput in byte units per second (Default: 10000KiB/s)
-
outboundNetwork
- Outbound network throughput in byte units per second (Default: 10000KiB/s)
Because Strimzi Kafka brokers are homogeneous, Cruise Control applies the same capacity limits to every broker it is monitoring.
An example Cruise Control brokerCapacity configuration using bibyte units
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
name: my-cluster
spec:
# ...
cruiseControl:
# ...
brokerCapacity:
disk: 100Gi
cpuUtilization: 100
inboundNetwork: 10000KiB/s
outboundNetwork: 10000KiB/s
# ...
Logging configuration
Cruise Control has its own configurable logger:
Cruise Control uses the Apache log4j
logger implementation.
Use the logging
property to configure loggers and logger levels.
You can set the log levels by specifying the logger and level directly (inline) or use a custom (external) ConfigMap.
If a ConfigMap is used, you set logging.name
property to the name of the ConfigMap containing the external logging configuration. Inside the ConfigMap, the logging configuration is described using log4j.properties
.
Here we see examples of inline
and external
logging.
Inline logging
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
# ...
spec:
cruiseControl:
# ...
logging:
type: inline
loggers:
cruisecontrol.root.logger: "INFO"
# ...
External logging
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
# ...
spec:
cruiseControl:
# ...
logging:
type: external
name: customConfigMap
# ...
To deploy Cruise Control to your Strimzi cluster, define the configuration using the cruiseControl
property in the Kafka
resource, and then create or update the resource.
Deploy one instance of Cruise Control per Kafka cluster.
Procedure
-
Edit the Kafka
resource and add the cruiseControl
property.
The properties you can configure are shown in this example configuration:
apiVersion: kafka.strimzi.io/v1beta1
kind: Kafka
metadata:
name: my-cluster
spec:
# ...
cruiseControl:
brokerCapacity: (1)
inboundNetwork: 10000KB/s
outboundNetwork: 10000KB/s
# ...
config: (2)
default.goals: >
com.linkedin.kafka.cruisecontrol.analyzer.goals.RackAwareGoal,
com.linkedin.kafka.cruisecontrol.analyzer.goals.ReplicaCapacityGoal
# ...
cpu.balance.threshold: 1.1
metadata.max.age.ms: 300000
send.buffer.bytes: 131072
# ...
resources: (3)
requests:
cpu: 200m
memory: 64Mi
limits:
cpu: 500m
memory: 128Mi
logging: (4)
type: inline
loggers:
cruisecontrol.root.logger: "INFO"
template: (5)
pod:
metadata:
labels:
label1: value1
securityContext:
runAsUser: 1000001
fsGroup: 0
terminationGracePeriodSeconds: 120
readinessProbe: (6)
initialDelaySeconds: 15
timeoutSeconds: 5
livenessProbe: (7)
initialDelaySeconds: 15
timeoutSeconds: 5
# ...
-
Specifies capacity limits for broker resources. For more information, see Capacity configuration.
-
Defines the Cruise Control configuration, including the default optimization goals (in default.goals
) and any customizations to the master optimization goals (in goals
) or the hard goals (in hard.goals
).
You can provide any standard Cruise Control configuration option apart from those managed directly by Strimzi.
For more information on configuring optimization goals, see Optimization goals overview.
-
CPU and memory resources reserved for Cruise Control. For more information, see CPU and memory resources.
-
Defined loggers and log levels added directly (inline) or indirectly (external) through a ConfigMap. A custom ConfigMap must be placed under the log4j.properties key. Cruise Control has a single logger named cruisecontrol.root.logger
. You can set the log level to INFO, ERROR, WARN, TRACE, DEBUG, FATAL or OFF. For more information, see Logging configuration.
-
Customization of deployment templates and pods.
-
Healthcheck readiness probes.
-
Healthcheck liveness probes.
-
Create or update the resource:
kubectl apply -f kafka.yaml
-
Verify that Cruise Control was successfully deployed:
kubectl get deployments -l app.kubernetes.io/name=strimzi
Auto-created 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.
Auto-created topic |
Created by |
Function |
strimzi.cruisecontrol.metrics
|
Strimzi Metrics Reporter |
Stores the raw metrics from the Metrics Reporter in each Kafka broker. |
strimzi.cruisecontrol.partitionmetricsamples
|
Cruise Control |
Stores the derived metrics for each partition. These are created by the Metric Sample Aggregator. |
strimzi.cruisecontrol.modeltrainingsamples
|
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.