Get up and running Apache Kafka using Strimzi on Kubernetes
Tags: kubernetes, kafka, strimzi, cloudnative
Published: 2021-08-26 06:21:16

It's first post on series of blog posts on Apache Kafka using [Strimzi](https://strimzi.io/) in Kubernetes. In this series we'll see how we can get up and running Apache Kafka using Strimzi on Kubernetes, export metrics, use exported metrics in [Prometheus](https://prometheus.io/) and finally build beautiful graphs in [Grafana](https://grafana.com/).

Perquisites:

[kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) 

Welcome to Strimzi:

Strimzi is an open source project licensed under Apache License 2.0 that is part of the [Cloud Native Computing Foundation](https://www.cncf.io/) (CNCF) as a sandbox project. Its main focus is running [Apache Kafka](https://kafka.apache.org/) on [Kubernetes](https://kubernetes.io/) while providing container images for Apache Kafka itself, [Zookeeper](https://zookeeper.apache.org/), and other components that are part of the Strimzi ecosystem.

Leveraging the [Kubernetes Operator](https://developers.redhat.com/topics/kubernetes/operators/) pattern, it addresses the whole lifecycle from creating, managing, and monitoring Kafka clusters to managing all the related entities like topics and users. You get a real Kubernetes-native experience for handling all of the components in the Apache Kafka ecosystem.


Get up and running Apache Kafka using Strimzi on Kubernetes:

Follow the simple steps to install Strimzi Kafka on Kubernetes:

1. Install Strimzi Operator, before running this command please make sure to create kafka namespace.

`kubectl create -f 'https://strimzi.io/install/latest?namespace=kafka'`
![Command output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/75kwr5q0kthm3yt9kuwg.png)

2. Install basic Kafka cluster and Zookeeper with metrics enabled. We'll see in future post how we can use exported metrics in Prometheus and also build dashboard on top of those metrics in Grafana.

`kubectl apply -f https://github.com/waqasdilawar/strimzi-kafka-k8s/blob/main/kafka/01-strimzi-kafka-with-metrics.yaml -n kafka`
![Command output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00y3xjrwh26if9kj1syj.png)

3. Try producing messages in a topic. Before producing message to a topic make sure you have Strimzi operator and it's different components are up and running as shown in below image.
![Everything is up and running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzclmc6zazdaom1ksmc0.png)
`kubectl -n kafka run kafka-producer -ti --image=quay.io/strimzi/kafka:0.25.0-kafka-2.8.0 --rm=true --restart=Never -- bin/kafka-console-producer.sh --broker-list my-cluster-kafka-bootstrap:9092 --topic my-topic`

4. In another terminal we can use a consumer to receive messages.

`kubectl -n kafka run kafka-consumer -ti --image=quay.io/strimzi/kafka:0.25.0-kafka-2.8.0 --rm=true --restart=Never -- bin/kafka-console-consumer.sh --bootstrap-server my-cluster-kafka-bootstrap:9092 --topic my-topic --from-beginning`

![Output of producer and consumer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37aj2mu1clbbq1cjc82i.png)

Enjoy your Apache Kafka cluster, running on Kubernetes!

Reference: [Source code](https://github.com/waqasdilawar/strimzi-kafka-k8s), [Strimzi Quick start](https://strimzi.io/quickstarts/)