Chapter 5. Using the Topic Operator
5.1. Topic Operator usage recommendations Copy linkLink copied to clipboard!
-
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 Copy linkLink copied to clipboard!
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
KafkaTopicCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIt is recommended that the topic name given is a valid OpenShift resource name, as it is then not necessary to set the
KafkaTopic.spec.topicNameproperty. 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
oc apply -f your-fileCopy to Clipboard Copied! Toggle word wrap Toggle overflow
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.3, “Cluster Operator”.
- For more information about deploying the Topic Operator using the Cluster Operator, see Section 2.9.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 Copy linkLink copied to clipboard!
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
KafkaTopicCopy to Clipboard Copied! Toggle word wrap Toggle overflow TipYou 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.ImportantIncreasing
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
oc apply -f your-fileCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
-
For more information about the schema for
KafkaTopics, seeKafkaTopicschema reference. - For more information about deploying a Kafka cluster, see Section 2.3, “Cluster Operator”.
- For more information about deploying the Topic Operator using the Cluster Operator, see Section 2.9.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 Copy linkLink copied to clipboard!
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. -
delete.topic.enable=true(default)
The delete.topic.enable property must be set to true in Kafka.spec.kafka.config. Otherwise, the steps outlined here will delete the KafkaTopic resource, but the Kafka topic and its data will remain. After reconciliation by the Topic Operator, the custom resource is then recreated.
Procedure
Delete the
KafkaTopicresource in OpenShift.On OpenShift this can be done using
oc:oc delete kafkatopic your-topic-name
oc delete kafkatopic your-topic-nameCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
- For more information about deploying a Kafka cluster using the Cluster Operator, see Section 2.3, “Cluster Operator”.
- For more information about deploying the Topic Operator using the Cluster Operator, see Section 2.9.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”.