// This module is included in the following assemblies:
//
// assembly-downgrading-kafka-versions.adoc

[id='proc-downgrading-brokers-older-kafka-{context}']

= Downgrading Kafka brokers and client applications

[role="_abstract"]
This procedure describes how you can downgrade a Strimzi Kafka cluster to a lower (previous) version of Kafka, such as downgrading from {KafkaVersionHigher} to {KafkaVersionLower}.

.Prerequisites

Before you downgrade the Strimzi Kafka cluster, check the following for the `Kafka` resource:

* IMPORTANT: xref:con-target-downgrade-version-{context}[Compatibility of Kafka versions].
* The Cluster Operator, which supports both versions of Kafka, is up and running.
* The `Kafka.spec.kafka.config` does not contain options that are not supported by the Kafka version being downgraded to.
* The `Kafka.spec.kafka.config` has a `log.message.format.version` and `inter.broker.protocol.version` that is supported by the Kafka version being downgraded to.
+
From Kafka 3.0.0, when the `inter.broker.protocol.version` is set to `3.0` or higher, the `log.message.format.version` option is ignored and doesn't need to be set.

.Procedure

. Update the Kafka cluster configuration.
+
[source,shell,subs=+quotes]
kubectl edit kafka _KAFKA-CONFIGURATION-FILE_

. Change the `Kafka.spec.kafka.version` to specify the previous version.
+
For example, if downgrading from Kafka {KafkaVersionHigher} to {KafkaVersionLower}:
+
[source,yaml,subs=attributes+]
----
apiVersion: {KafkaApiVersion}
kind: Kafka
spec:
  # ...
  kafka:
    version: {KafkaVersionLower} <1>
    config:
      log.message.format.version: "{InterBrokerVersionLower}" <2>
      inter.broker.protocol.version: "{InterBrokerVersionLower}" <3>
      # ...
----
<1> Kafka version is changed to the previous version.
<2> Message format version is unchanged.
<3> Inter-broker protocol version is unchanged.
+
NOTE: The value of `log.message.format.version` and `inter.broker.protocol.version` must be strings to prevent them from being interpreted as floating point numbers.

. If the image for the Kafka version is different from the image defined in `STRIMZI_KAFKA_IMAGES` for the Cluster Operator, update `Kafka.spec.kafka.image`.
+
See xref:con-versions-and-images-str[]

. Save and exit the editor, then wait for rolling updates to complete.
+
Check the update in the logs or by watching the pod state transitions:
+
[source,shell,subs=+quotes]
----
kubectl logs -f _CLUSTER-OPERATOR-POD-NAME_ | grep -E "Kafka version downgrade from [0-9.]+ to [0-9.]+, phase ([0-9]+) of \1 completed"
----
+
[source,shell,subs=+quotes]
----
kubectl get pod -w
----
+
Check the Cluster Operator logs for an `INFO` level message:
+
[source,shell,subs=+quotes]
----
Reconciliation #_NUM_(watch) Kafka(_NAMESPACE_/_NAME_): Kafka version downgrade from _FROM-VERSION_ to _TO-VERSION_, phase 1 of 1 completed
----

. Downgrade all client applications (consumers) to use the previous version of the client binaries.
+
The Kafka cluster and clients are now using the previous Kafka version.

. If you are reverting back to a version of Strimzi earlier than {ConvertAfterProductVersion}, which uses ZooKeeper for the storage of topic metadata, delete the internal topic store topics from the Kafka cluster.
+
[source,shell,subs=attributes+]
----
kubectl run kafka-admin -ti --image={DockerKafkaImageCurrent} --rm=true --restart=Never -- ./bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic __strimzi-topic-operator-kstreams-topic-store-changelog --delete && ./bin/kafka-topics.sh --bootstrap-server localhost:9092 --topic __strimzi_store_topic --delete
----

[role="_additional-resources"]
.Additional resources
* link:{BookURLUsing}#ref-topic-operator-store-{context}[Topic Operator topic store^]
