Created
January 22, 2025 13:37
-
-
Save aks2291/234f281301c81964b23f723eca0e391b to your computer and use it in GitHub Desktop.
Kafka Setup with UI dashboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| services: | |
| zookeeper: | |
| image: confluentinc/cp-zookeeper:latest | |
| environment: | |
| ZOOKEEPER_CLIENT_PORT: 2181 | |
| ZOOKEEPER_TICK_TIME: 2000 | |
| ports: | |
| - '2181:2181' | |
| kafka: | |
| image: confluentinc/cp-kafka:latest | |
| environment: | |
| KAFKA_BROKER_ID: 1 | |
| KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | |
| KAFKA_LISTENERS: INSIDE://0.0.0.0:9092,OUTSIDE://0.0.0.0:9094 | |
| KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9092,OUTSIDE://localhost:9094 | |
| KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT | |
| KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE # Set this to INSIDE or OUTSIDE | |
| KAFKA_ZOOKEEPER_SESSION_TIMEOUT_MS: 6000 | |
| KAFKA_ZOOKEEPER_CONNECTION_TIMEOUT_MS: 6000 | |
| KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | |
| ports: | |
| - '9092:9092' | |
| - '9094:9094' | |
| depends_on: | |
| - zookeeper | |
| kafka-ui: | |
| image: provectuslabs/kafka-ui:latest | |
| ports: | |
| - "8080:8080" | |
| environment: | |
| KAFKA_CLUSTERS_0_NAME: local | |
| KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9092 | |
| KAFKA_CLUSTERS_0_READONLY: "false" | |
| AUTH_TYPE: "LOGIN_FORM" | |
| SPRING_SECURITY_USER_NAME: admin | |
| SPRING_SECURITY_USER_PASSWORD: pass | |
| depends_on: | |
| - kafka |
Author
Author
Kafka setup in KRAFT Mode
This setup doesn't require zookeeper (Not recommended for production)
version: '3.8'
services:
kafka:
image: confluentinc/cp-kafka:latest
container_name: kafka-kraft
environment:
CLUSTER_ID: "kraft-cluster-1"
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: "controller,broker"
KAFKA_LISTENERS: INSIDE://0.0.0.0:9092,OUTSIDE://0.0.0.0:9094,CONTROLLER://0.0.0.0:9093
KAFKA_CONTROLLER_QUORUM_VOTERS: "1@localhost:9093"
KAFKA_CONTROLLER_LISTENER_NAMES: "CONTROLLER"
KAFKA_ADVERTISED_LISTENERS: INSIDE://kafka:9092,OUTSIDE://localhost:9094
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INSIDE:PLAINTEXT,OUTSIDE:PLAINTEXT,CONTROLLER:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: INSIDE
ports:
- '9092:9092'
- '9094:9094'
- '9093:9093' # Add port for controller listener
kafka-ui:
image: provectuslabs/kafka-ui:latest
ports:
- "8080:8080"
environment:
KAFKA_CLUSTERS_0_NAME: local
KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS: kafka:9092
KAFKA_CLUSTERS_0_READONLY: "false"
AUTH_TYPE: "LOGIN_FORM"
SPRING_SECURITY_USER_NAME: admin
SPRING_SECURITY_USER_PASSWORD: pass
depends_on:
- kafka
How to use it
Everything will be the same as the above with zookeeper setup for deploying and way to connect to the broker
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Kafka with Zookeeper and UI Setup
This guide helps you run Kafka, Zookeeper, and Kafka-UI locally using Docker Compose and provides instructions on how to use the Kafka-UI and connect Kafka from external services.
Prerequisites
Steps to Run Kafka and UI
Save the
docker-compose.ymlFile:Create a file named
docker-compose.ymland paste the gist contentStart the Services:
Run the following command in the same directory as your
docker-compose.ymlfile:Verify the Services:
2181.9092(internal) and9094(external).http://localhost:8080in your browser. Login with:adminpassUsing Kafka-UI
Login to the UI:
Navigate to
http://localhost:8080and enter the credentials.Browse Topics:
Send Messages:
Monitor Consumers:
Connecting Kafka from External Services
To connect an external service to Kafka, use the advertised listener
OUTSIDE://localhost:9094.Here’s an example of connecting from a Node.js application using the
kafkajslibrary:Stopping the Services
To stop the containers, run:
Notes
9094is accessible from external services.localhostwith the machine's IP address inKAFKA_ADVERTISED_LISTENERSand your service configurations.