Strimzi

Starting OKD

This assumes that you have the latest version of the oc binary, which you can get here.

oc cluster up

This will start a local installation of OKD, the Origin Community Distribution of Kubernetes that powers Red Hat OpenShift. Once this is completed, login as a cluster-admin user:

# Install as cluster-admin
oc login -u system:admin

Applying Strimzi installation file

Next we apply the Strimzi install files, including ClusterRoles, ClusterRoleBindings and some Custom Resource Definitions (CRDs). The CRDs define the schemas used for declarative management of the Kafka cluster, Kafka topics and users.

oc apply -f https://github.com/strimzi/strimzi-kafka-operator/releases/download/0.14.0/strimzi-cluster-operator-0.14.0.yaml -n myproject

Provision the Apache Kafka cluster

After that we feed Strimzi with a simple Custom Resource, which will then give you a small persistent Apache Kafka Cluster with one node for each, Apache Zookeeper and Apache Kafka:

# Apply the `Kafka` Cluster CR file
oc apply -f https://raw.githubusercontent.com/strimzi/strimzi-kafka-operator/0.14.0/examples/kafka/kafka-persistent-single.yaml -n myproject 

We now need to wait while OpenShift starts the required pods, services and so on:

oc wait kafka/my-cluster --for=condition=Ready --timeout=300s -n myproject

The above command might timeout if you’re downloading images over a slow connection. If that happens you can always run it again.

Send and receive messages

Once the cluster is running, you can run a simple producer to send messages to Kafka topic (the topic will be automatically created):

oc -n myproject run kafka-producer -ti --image=strimzi/kafka:0.14.0-kafka-2.3.0 --rm=true --restart=Never -- bin/kafka-console-producer.sh --broker-list my-cluster-kafka-bootstrap:9092 --topic my-topic

And to receive them in a different terminal you can run:

oc -n myproject run kafka-consumer -ti --image=strimzi/kafka:0.14.0-kafka-2.3.0 --rm=true --restart=Never -- bin/kafka-console-consumer.sh --bootstrap-server my-cluster-kafka-bootstrap:9092 --topic my-topic --from-beginning

Enjoy your Apache Kafka cluster, running on OKD!