Overview
This template provides a production‑ready Apache Kafka stack as a Monk runnable. You can:- Run it directly to get a managed Kafka cluster with ZooKeeper coordination
- Inherit it in your own runnable to seamlessly add event streaming capabilities to your stack
What this template manages
- Kafka broker containers (
confluentinc/cp-kafkaimage, configurable tag) - ZooKeeper ensemble for cluster coordination (
confluentinc/cp-zookeeperimage, configurable tag) - Network services on ports 9092 (Kafka) and 2181 (ZooKeeper)
- Persistent volumes for Kafka data and ZooKeeper state
- Cluster configuration and topic management
Quick start (run directly)
- Load templates
- Run Kafka stack with defaults
- Customize configuration (recommended via inheritance)
variables. For production use, inherit and configure:
- Preferred: inherit and set variables as shown below
- Alternative: fork/clone and edit the
variablesinkafka.yamlandstack.yaml, thenmonk load MANIFESTand run
localhost:9092 (or the runnable hostname inside Monk networks) to produce and consume messages.
Configuration
Key variables you can customize in this template:${monk-volume-path}/kafka and ${monk-volume-path}/zookeeper on the host.
Use by inheritance (recommended for apps)
Inherit the Kafka stack in your application and declare a connection. Example:Ports and connectivity
- Service:
kafkaon TCP port9092(broker) - Service:
zookeeperon TCP port2181(coordination) - From other runnables in the same process group, use
connection-hostname("\<connection-name>")to resolve the Kafka broker host - External clients can connect via the advertised listeners configuration
Persistence and configuration
- Kafka data path:
${monk-volume-path}/kafka:/var/lib/kafka/data - ZooKeeper data path:
${monk-volume-path}/zookeeper:/var/lib/zookeeper - Ensure the host volumes are writable by the container user
Features
- High-throughput messaging (millions of messages per second)
- Fault-tolerant storage with replication
- Stream processing (Kafka Streams)
- Scalable architecture (horizontal scaling)
- Exactly-once semantics
- Multiple consumer groups
- Built-in partitioning for parallelism
Related templates
- Use with microservices for async communication
- Combine with stream processing frameworks (Kafka Streams, Flink, Spark Streaming)
- Integrate with monitoring (
prometheus-grafana/) for metrics and alerting - Pair with schema registry for data governance
Troubleshooting
- Ensure ZooKeeper is running before Kafka starts. The stack handles this dependency automatically.
- If connection fails, verify
KAFKA_ADVERTISED_LISTENERSmatches your network configuration - For external access, ensure firewall rules allow traffic on port 9092
- Check logs:
- To check ZooKeeper separately: