Create topic 🔗︎

You can create Kafka topics either:

  • directly against the cluster with command line utilities, or
  • via the KafkaTopic CRD.

Below is an example KafkaTopic CR you can apply with kubectl.

cat << EOF | kubectl apply -n kafka -f -
apiVersion: kafka.banzaicloud.io/v1alpha1
kind: KafkaTopic
metadata:
    name: my-topic
spec:
    clusterRef:
        name: kafka
    name: my-topic
    partitions: 1
    replicationFactor: 1
    config:
        "retention.ms": "604800000"
        "cleanup.policy": "delete"
EOF

For a full list of configuration options, see the official Kafka documentation.

Update topic 🔗︎

If you want to update the configuration of the topic after it’s been created, you can either:

  • edit the manifest and run kubectl apply again, or
  • run kubectl edit -n kafka kafkatopic example-topic and then update the configuration in the editor that gets spawned.

You can increase the partition count for a topic the same way, or by running the following one-liner using patch:

kubectl patch -n kafka kafkatopic example-topic --patch '{"spec": {"partitions": 5}}' --type=merge

kafkatopic.kafka.banzaicloud.io/example-topic patched

Note: Topics created by the Koperator are not enforced in any way. From the Kubernetes perspective, Kafka Topics are external resources.