This gist describes how to create a Kafka cluster on Kubernetes with minimal effort.
Dislike to incubator/kafka helm chart, this approach uses wurstmeister/kafka Docker image or its GraalVM equivalent, dongjinleekr/kafka.
Note: This configuration is intended for dev or testing purpose; it may be used in production environment, but I can't give any guarantees in that respect.
Install Zookeeper with the following helm command:
# Add helm incubator repository
helm repo add incubator https://charts.helm.sh/incubator
# Install Zookeeper cluster named 'test-zookeeper'
helm install test-zookeeper incubator/zookeeper
To test whether the Zookeeper cluster runs correctly, run ls
from the Zookeeper cli client.
kubectl -n default exec -it test-zookeeper-0 -- bin/zkCli.sh -server test-zookeeper-0.test-zookeeper-headless:2181,test-zookeeper-1.test-zookeeper-headless:2181 ls /
The following command creates a kafka cluster named 'test-kafka', on top of 'test-zookeeper' Zookeeper cluster.
kubectl apply -f kafka.yaml
To install Kafka client pod or Kafkacat pod, run:
# install kafka client pod
kubectl apply -f kafka-client.yaml
# install kafkacat pod
kubectl apply -f kafkacat.yaml
To test whether the Kafka cluster runs correctly, run:
# list topics with kafka client
kubectl -n default exec -it kafka-client -- kafka-topics --bootstrap-server test-kafka-0.test-kafka-headless:9092,test-kafka-1.test-kafka-headless:9092 --list --topic
# list topics with kafkacat
kubectl -n default exec -it kafkacat -- kafkacat -b test-kafka-0.test-kafka-headless:9092,test-kafka-1.test-kafka-headless:9092,test-kafka-2.test-kafka-headless:9092,test-kafka-3.test-kafka-headless:9092 -L