Kafka Cluster with Strimzi¶
Strimzi provides a way to run Apache Kafka on OpenShift via the Strimzi Cluster Operator. It manages Kafka clusters, topics, users, and connectors using custom resources.
Note
This page uses the community Strimzi operator from community-operators. It is not Red Hat Streams for Apache Kafka. Use Red Hat Streams for Apache Kafka when the customer needs a supported Kafka operator.
Prerequisites¶
- Cluster-admin access (for installing the operator)
- Sufficient cluster resources (minimum 3 broker nodes recommended for production)
Install the Strimzi Operator¶
-
Create a namespace for the Kafka cluster:
-
Install Strimzi from the Software Catalog:
-
Wait for the operator to be ready:
The phase should show
Succeeded.
Deploy a Kafka Cluster¶
Strimzi now requires KRaft (no ZooKeeper). Create a dual-role node pool and a Kafka cluster:
-
Apply the Kafka cluster manifest:
apiVersion: kafka.strimzi.io/v1beta2 kind: KafkaNodePool metadata: name: dual-role namespace: kafka labels: strimzi.io/cluster: my-cluster spec: replicas: 3 roles: - controller - broker resources: requests: memory: "2Gi" cpu: "500m" limits: memory: "4Gi" cpu: "1" storage: type: jbod volumes: - id: 0 type: persistent-claim size: 10Gi kraftMetadata: shared deleteClaim: false --- apiVersion: kafka.strimzi.io/v1beta2 kind: Kafka metadata: name: my-cluster namespace: kafka annotations: strimzi.io/node-pools: enabled strimzi.io/kraft: enabled spec: kafka: version: 4.2.0 # Match to your Strimzi operator version metadataVersion: 4.2-IV1 # Can be omitted to let Strimzi default it listeners: - name: plain port: 9092 type: internal tls: false - name: tls port: 9093 type: internal tls: true config: offsets.topic.replication.factor: 3 transaction.state.log.replication.factor: 3 transaction.state.log.min.isr: 2 default.replication.factor: 3 min.insync.replicas: 2 entityOperator: topicOperator: {} userOperator: {}Kafka and Metadata Versions
The
versionandmetadataVersionvalues must match your installed Strimzi operator. Check supported versions:oc get csv -n openshift-operators | grep strimzi. See Strimzi supported versions for the compatibility matrix. -
Wait for the cluster to become ready:
-
Verify all pods are running:
You should see pods for the dual-role brokers and the Entity Operator.
Create a Topic¶
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaTopic
metadata:
name: my-topic
namespace: kafka
labels:
strimzi.io/cluster: my-cluster
spec:
partitions: 3
replicas: 3
config:
retention.ms: 604800000
Test with a Producer and Consumer¶
-
Start a console producer:
-
In a separate terminal, start a console consumer:
Expose Kafka Outside the Cluster (Optional)¶
To access Kafka from outside OpenShift, add a Route listener to the existing Kafka CR. Do not apply the snippet below as a standalone resource — it would replace your working cluster.
oc patch kafka my-cluster -n kafka --type merge -p '
spec:
kafka:
listeners:
- name: plain
port: 9092
type: internal
tls: false
- name: tls
port: 9093
type: internal
tls: true
- name: external
port: 9094
type: route
tls: true
'
Retrieve the bootstrap address:
oc get kafka my-cluster -n kafka -o jsonpath='{.status.listeners[?(@.name=="external")].bootstrapServers}'