Chapter 5. Using the Topic Operator
5.1. Topic Operator usage recommendations
-
Be consistent and always operate on
KafkaTopicresources or always operate on topics directly. Avoid routinely using both methods for a given topic. When creating a
KafkaTopicresource:- Remember that the name cannot be changed later.
-
Choose a name for the
KafkaTopicresource that reflects the name of the topic it describes. -
Ideally the
KafkaTopic.metadata.nameshould be the same as itsspec.topicName. To do this, the topic name will have to be a valid Kubernetes resource name.
When creating a topic:
- Remember that the name cannot be changed later.
-
It is best to use a name that is a valid Kubernetes resource name, otherwise the operator will have to modify the name when creating the corresponding
KafkaTopic.
5.2. Creating a topic
This procedure describes how to create a Kafka topic using a KafkaTopic OpenShift resource.
Prerequisites
- A running Kafka cluster.
- A running Topic Operator.
Procedure
Prepare a file containing the
KafkaTopicto be createdAn example
KafkaTopicapiVersion: kafka.strimzi.io/v1alpha1 kind: KafkaTopic metadata: name: orders labels: strimzi.io/cluster: my-cluster spec: partitions: 10 replicas: 2NoteIt is recommended to use a topic name that is a valid OpenShift resource name. Doing this means that it is not necessary to set the
KafkaTopic.spec.topicNameproperty. In any case theKafkaTopic.spec.topicNamecannot be changed after creation.NoteThe
KafkaTopic.spec.partitionscannot be decreased.Create the
KafkaTopicresource in OpenShift.On OpenShift this can be done using
oc apply:oc apply -f your-file
Additional resources
-
For more information about the schema for
KafkaTopics, seeKafkaTopicschema reference. - For more information about deploying a Kafka cluster using the Cluster Operator, see Section 2.2, “Cluster Operator”.
- For more information about deploying the Topic Operator using the Cluster Operator, see Section 2.7.2, “Deploying the Topic Operator using the Cluster Operator”.
- For more information about deploying the standalone Topic Operator, see Section 4.2.5, “Deploying the standalone Topic Operator”.
5.3. Changing a topic
This procedure describes how to change the configuration of an existing Kafka topic by using a KafkaTopic OpenShift resource.
Prerequisites
- A running Kafka cluster.
- A running Topic Operator.
-
An existing
KafkaTopicto be changed.
Procedure
Prepare a file containing the desired
KafkaTopicAn example
KafkaTopicapiVersion: kafka.strimzi.io/v1alpha1 kind: KafkaTopic metadata: name: orders labels: strimzi.io/cluster: my-cluster spec: partitions: 16 replicas: 2TipYou can get the current version of the resource using
oc get kafkatopic orders -o yaml.NoteChanging topic names using the
KafkaTopic.spec.topicNamevariable and decreasing partition size using theKafkaTopic.spec.partitionsvariable is not supported by Kafka.CautionIncreasing
spec.partitionsfor topics with keys will change how records are partitioned, which can be particularly problematic when the topic uses semantic partitioning.Update the
KafkaTopicresource in OpenShift.On OpenShift this can be done using
oc apply:oc apply -f your-file
Additional resources
-
For more information about the schema for
KafkaTopics, seeKafkaTopicschema reference. - For more information about deploying a Kafka cluster, see Section 2.2, “Cluster Operator”.
- For more information about deploying the Topic Operator using the Cluster Operator, see Section 2.7.2, “Deploying the Topic Operator using the Cluster Operator”.
- For more information about creating a topic using the Topic Operator, see Section 5.2, “Creating a topic”.
5.4. Deleting a topic
This procedure describes how to delete a Kafka topic using a KafkaTopic OpenShift resource.
Prerequisites
- A running Kafka cluster.
- A running Topic Operator.
-
An existing
KafkaTopicto be deleted.
Procedure
Delete the
KafkaTopicresource in OpenShift.On OpenShift this can be done using
oc:oc delete kafkatopic your-topic-nameNoteWhether the topic can actually be deleted depends on the value of the
delete.topic.enableKafka broker configuration, specified in theKafka.spec.kafka.configproperty.
Additional resources
- For more information about deploying a Kafka cluster using the Cluster Operator, see Section 2.2, “Cluster Operator”.
- For more information about deploying the Topic Operator using the Cluster Operator, see Section 2.7.2, “Deploying the Topic Operator using the Cluster Operator”.
- For more information about creating a topic using the Topic Operator, see Section 5.2, “Creating a topic”.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.