// Module included in the following assemblies:
//
// assembly-using-the-topic-operator.adoc

[id='creating-a-topic-{context}']
= Creating a topic

This procedure describes how to create a Kafka topic using a `KafkaTopic` Kubernetes resource.

.Prerequisites

* A running Kafka cluster.
* A running Topic Operator (typically xref:assembly-kafka-entity-operator-deployment-configuration-kafka[deployed with the Entity Operator]).

.Procedure

. Prepare a file containing the `KafkaTopic` to be created
+
.An example `KafkaTopic`
[source,yaml,subs="attributes+"]
----
apiVersion: {KafkaTopicApiVersion}
kind: KafkaTopic
metadata:
  name: orders
  labels:
    strimzi.io/cluster: my-cluster
spec:
  partitions: 10
  replicas: 2
----
+
NOTE: It is recommended that the topic name given is a valid Kubernetes resource name, as it is then not necessary to set the `KafkaTopic.spec.topicName` property. The `KafkaTopic.spec.topicName` _cannot_ be changed after creation.
+
NOTE: The `KafkaTopic.spec.partitions` cannot be decreased.

. Create the `KafkaTopic` resource in Kubernetes.
+
This can be done using `kubectl apply`:
+
[source,shell,subs=+quotes]
kubectl apply -f _your-file_

.Additional resources
* For more information about the schema for `KafkaTopics`, see xref:type-KafkaTopic-reference[`KafkaTopic` schema reference].
* For more information about deploying a Kafka cluster using the Cluster Operator, see xref:cluster-operator-str[Deploying the Cluster Operator].
* For more information about deploying the Topic Operator using the Cluster Operator, see xref:deploying-the-topic-operator-using-the-cluster-operator-str[Deploying the Topic Operator using the Cluster Operator].
* For more information about deploying the standalone Topic Operator, see xref:deploying-the-topic-operator-standalone-{context}[Deploying the standalone Topic Operator].
