// Module included in the following assemblies:
//
// assembly-kafka-rack.adoc

[id='ref-kafka-rack-{context}']
= Kafka rack awareness

Kafka rack awareness can be configured in the `rack` property of `Kafka.spec.kafka`.
The `rack` object has one mandatory field named `topologyKey`, which needs to match one of the labels assigned to the Kubernetes cluster nodes.
The label is used by Kubernetes when scheduling the Kafka broker pods to nodes.

If the Kubernetes cluster is running on a cloud provider platform, that label should represent the availability zone where the node is running.
If the Kubernetes cluster is running on a cloud provider platform, that label should represent the availability zone where the node is running.
Usually, the nodes are labeled with `topology.kubernetes.io/zone` label (or `failure-domain.beta.kubernetes.io/zone` on older Kubernetes versions) that can be used as the `topologyKey` value.
This will have the effect of spreading the broker pods across zones, and also setting the brokers' `broker.rack` configuration parameter inside Kafka broker.

In the following example, the `topology.kubernetes.io/zone` node label is used for scheduling Kafka broker Pods.
Consult your Kubernetes administrator about the label which should be used.

.Example of a `Kafka` resource with the `rack` feature enabled
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaApiVersion}
kind: Kafka
metadata:
  name: my-cluster
spec:
  kafka:
    # ...
    rack:
      topologyKey: topology.kubernetes.io/zone
    # ...
----

== Configuring init container image

When the Kafka rack feature is enabled, Kafka broker pods will use init container which will collect the labels from the Kubernetes cluster nodes.
The container image which will be used for this container can be configured using the `brokerRackInitImage` property in `Kafka.spec.kafka`.
When the `brokerRackInitImage` field is missing, the following images will be used (in the order of priority):

. Container image specified in `STRIMZI_DEFAULT_KAFKA_INIT_IMAGE` environment variable in Cluster Operator configuration.
. `{DockerKafkaInit}` container image.

WARNING: Overriding container images is recommended only in situations where you need to use a different container registry.
For example, because your network does not allow access to the container repository used by Strimzi.
In such case, you should either copy the Strimzi images or build them from source.
In case the configured image is not compatible with Strimzi images, it might not work properly.

.Example of `brokerRackInitImage` configuration
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaApiVersion}
kind: Kafka
metadata:
  name: my-cluster
spec:
  kafka:
    # ...
    brokerRackInitImage: my-org/my-image:latest
    # ...
----
