Starting Minikube

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

minikube start --memory=4096 # 2GB default memory isn't always enough

NOTE: Make sure to start minikube with your configured VM. If need help look at the documentation for more.

Once Minikube is started, let’s create our kafka namespace:

kubectl create namespace kafka

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.

curl -L \
  | sed 's/namespace: .*/namespace: kafka/' \
  | kubectl apply -f - -n kafka 

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
kubectl apply -f -n kafka 

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

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

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 a Kafka topic (the topic will be automatically created):

kubectl -n kafka run kafka-producer -ti --image=strimzi/kafka:0.16.2-kafka-2.4.0 --rm=true --restart=Never -- bin/ --broker-list my-cluster-kafka-bootstrap:9092 --topic my-topic

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

kubectl -n kafka run kafka-consumer -ti --image=strimzi/kafka:0.16.2-kafka-2.4.0 --rm=true --restart=Never -- bin/ --bootstrap-server my-cluster-kafka-bootstrap:9092 --topic my-topic --from-beginning

Enjoy your Apache Kafka cluster, running on Minikube!