-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add kafka ngrok example #12
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
= Docker Compose for running Apache Kafka locally, accessible from the internet using ngrok | ||
|
||
image::https://rmoff.net/images/2023/11/ngrok02.webp[Overview diagram] | ||
|
||
_For details of how this works, see https://rmoff.net/2023/11/01/using-apache-kafka-with-ngrok/[this blog] (and take note of https://rmoff.net/2024/05/03/ngrok-dns-headaches/[possible problems] you might encounter)._ | ||
|
||
To use this you need to https://dashboard.ngrok.com/signup[create an ngrok account] and add a file called `.env` in this folder with the following entry: | ||
|
||
[source,bash] | ||
---- | ||
NGROK_AUTH_TOKEN=<your_token> | ||
---- | ||
|
||
Bring up the Kafka and ngrok stack with | ||
|
||
[source,bash] | ||
---- | ||
docker compose up | ||
---- | ||
|
||
Once up, find out your Kafka broker host/post that is available on the internet: | ||
|
||
[source,bash] | ||
---- | ||
curl -s localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url' | sed 's/tcp:\/\///g' | ||
---- | ||
|
||
WARNING: There is **NO SECURITY** defined on this Kafka cluster. Anyone scanning the ngrok address/port may find this and be able to access your data. | ||
|
||
https://github.com/edenhill/kcat[kcat] is included. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
version: '3.8' | ||
services: | ||
ngrok: | ||
image: ngrok/ngrok:latest | ||
container_name: ngrok | ||
# Sign up for an ngrok account at https://dashboard.ngrok.com/signup | ||
# Get your auth-token from https://dashboard.ngrok.com/get-started/your-authtoken | ||
# and either put it directly in the file here, or write it to a .env file in | ||
# the same folder as this Docker Compose file in the form | ||
# NGROK_AUTH_TOKEN=your_token_value | ||
command: tcp broker:9092 --log stdout --authtoken $NGROK_AUTH_TOKEN | ||
ports: | ||
- 4040:4040 # Web dashboard for ngrok | ||
|
||
zookeeper: | ||
image: confluentinc/cp-zookeeper:7.5.1 | ||
container_name: zookeeper | ||
environment: | ||
ZOOKEEPER_CLIENT_PORT: 2181 | ||
ZOOKEEPER_TICK_TIME: 2000 | ||
|
||
broker: | ||
image: confluentinc/cp-kafka:7.5.1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about using the new official Apache image instead? And maybe no ZK? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure. next time :) this is just to get it out the door. |
||
container_name: broker | ||
depends_on: | ||
- zookeeper | ||
- ngrok | ||
environment: | ||
KAFKA_BROKER_ID: 1 | ||
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | ||
KAFKA_LISTENERS: DOCKER://broker:29092, NGROK://broker:9092 | ||
KAFKA_ADVERTISED_LISTENERS: DOCKER://broker:29092 | ||
KAFKA_INTER_BROKER_LISTENER_NAME: DOCKER | ||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: DOCKER:PLAINTEXT,NGROK:PLAINTEXT | ||
KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true" | ||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 | ||
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 | ||
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 | ||
entrypoint: | ||
- /bin/sh | ||
- -c | ||
- | | ||
echo "Waiting for ngrok tunnel to be created" | ||
while : ; do | ||
curl_status=$$(curl -s -o /dev/null -w %{http_code} http://ngrok:4040/api/tunnels/command_line) | ||
echo -e $$(date) "\tTunnels API HTTP state: " $$curl_status " (waiting for 200)" | ||
if [ $$curl_status -eq 200 ] ; then | ||
break | ||
fi | ||
sleep 5 | ||
done | ||
echo "ngrok tunnel is up" | ||
# My kingdom for a jq 😿 | ||
NGROK_LISTENER=$(curl -s http://ngrok:4040/api/tunnels/command_line | grep -Po '"public_url":.*?[^\\]",' | cut -d':' -f2- | tr -d ',"' | sed 's/tcp:\/\//NGROK:\/\//g') | ||
echo $$NGROK_LISTENER | ||
export KAFKA_ADVERTISED_LISTENERS="$$KAFKA_ADVERTISED_LISTENERS, $$NGROK_LISTENER" | ||
echo "KAFKA_ADVERTISED_LISTENERS is set to " $$KAFKA_ADVERTISED_LISTENERS | ||
/etc/confluent/docker/run | ||
|
||
kcat: | ||
image: edenhill/kcat:1.7.1 | ||
container_name: kcat | ||
restart: no | ||
entrypoint: tail -f /dev/null | ||
|
||
networks: | ||
default: | ||
name: zaphod |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to call this out. Alternatively, I have a set-up for basic auth here. Maybe worth adopting. Still not production-grade or anything, but it's at least not leaving the house completely unlocked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that setup work with the Confluent images?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, never used those ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kk. for now I just wanna get this into the repo. maybe on the boston flight I will improve it :)