// This module is included in the following assemblies:
//
// assembly-cruise-control-concepts.adoc

[id='proc-deploying-cruise-control-{context}']
= Deploying Cruise Control

[role="_abstract"]
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.

.Prerequisites

* A Kubernetes cluster
* A running Cluster Operator

.Procedure

. Edit the `Kafka` resource and add the `cruiseControl` property.
+
The properties you can configure are shown in this example configuration:
+
[source,yaml,subs="attributes+"]
----
apiVersion: {KafkaApiVersion}
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: 1
        memory: 512Mi
      limits:
        cpu: 2
        memory: 2Gi
    logging: # <4>
        type: inline
        loggers:
          rootLogger.level: "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
# ...
----
<1> Specifies capacity limits for broker resources. For more information, see xref:capacity-configuration[Capacity configuration].
<2> Defines the Cruise Control configuration, including the default optimization goals (in `default.goals`) and any customizations to the main optimization goals (in `goals`) or the hard goals (in `hard.goals`).
You can provide any xref:ref-cruise-control-configuration-{context}[standard Cruise Control configuration option] apart from those managed directly by Strimzi.
For more information on configuring optimization goals, see xref:con-optimization-goals-{context}[].
<3> CPU and memory resources reserved for Cruise Control. For more information, see xref:con-common-configuration-resources-reference[].
<4> 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 `rootLogger.level`. You can set the log level to INFO, ERROR, WARN, TRACE, DEBUG, FATAL or OFF. For more information, see xref:logging-configuration[Logging configuration].
<5> xref:assembly-customizing-kubernetes-resources-str[Customization of deployment templates and pods].
<6> xref:con-common-configuration-healthchecks-reference[Healthcheck readiness probes].
<7> xref:con-common-configuration-healthchecks-reference[Healthcheck liveness probes].

. Create or update the resource:
+
[source,shell,subs="+quotes"]
----
kubectl apply -f _kafka.yaml_
----

. Check the status of the deployment:
+
[source,shell,subs="+quotes"]
----
kubectl get deployments -n _<my_cluster_operator_namespace>_
----
+
.Output shows the deployment name and readiness
[source,shell,subs="+quotes"]
----
NAME                      READY  UP-TO-DATE  AVAILABLE
my-cluster-cruise-control 1/1    1           1
----
+
`my-cluster` is the name of the Kafka cluster.
+
`READY` shows the number of replicas that are ready/expected.
The deployment is successful when the `AVAILABLE` output shows `1`.

[discrete]
== 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. You can change the name of the topic using the specified configuration option.

.Auto-created topics
[cols="1m,1m,1,3",options="header",stripes="none",separator=¦]
|===

¦Auto-created topic configuration
¦Default topic name
¦Created by
¦Function

¦metric.reporter.topic
¦strimzi.cruisecontrol.metrics
¦Strimzi Metrics Reporter
¦Stores the raw metrics from the Metrics Reporter in each Kafka broker.

¦partition.metric.sample.store.topic
¦strimzi.cruisecontrol.partitionmetricsamples
¦Cruise Control
¦Stores the derived metrics for each partition. These are created by the link:https://github.com/linkedin/cruise-control/wiki/Overview#metric-sample-aggregator[Metric Sample Aggregator^].

¦broker.metric.sample.store.topic
¦strimzi.cruisecontrol.modeltrainingsamples
¦Cruise Control
¦Stores the metrics samples used to create the link:https://github.com/linkedin/cruise-control/wiki/Overview#cluster-workload-model[Cluster Workload Model^].

|===

To prevent the removal of records that are needed by Cruise Control, log compaction is disabled in the auto-created topics.

NOTE: 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 xref:proc-generating-optimization-proposals-{context}[generate optimization proposals].

[role="_additional-resources"]
.Additional resources
* xref:type-CruiseControlTemplate-reference[].
