Skip to content
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

Support kafka kraft without zookeeper #678

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,25 @@ Older compose files using the short-version of port mapping may encounter Kafka

See the included sample compose file ```docker-compose-swarm.yml```

## Without Zookeeper

If you need to enable Kraft support, set the following environments (3 nodes):

first, Generate a cluster ID

```
docker run --rm wurstmeister/kafka:2.8.0 kafka-storage.sh random-uuid
```

then, set the following environments (3 nodes):

```
KAFKA_WITHOUT_ZOOKEEPER: "true"
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092,CONTROLLER://:9093
KAFKA_CONTROLLER_QUORUM_VOTERS: 1\@kafka1:9093,2\@kafka2:9093,3\@kafka3:9093
CLUSTER_UUID: <generated cluster id>
```

## Release process

See the [wiki](https://github.com/wurstmeister/kafka-docker/wiki/ReleaseProcess) for information on adding or updating versions to release to Dockerhub.
Expand Down
24 changes: 20 additions & 4 deletions start-kafka.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ fi
# Store original IFS config, so we can restore it at various stages
ORIG_IFS=$IFS

if [[ -z "$KAFKA_ZOOKEEPER_CONNECT" ]]; then
if [[ -z "$KAFKA_WITHOUT_ZOOKEEPER" && -z "$KAFKA_ZOOKEEPER_CONNECT" ]]; then
echo "ERROR: missing mandatory config: KAFKA_ZOOKEEPER_CONNECT"
exit 1
fi

if [[ ! -z "$KAFKA_WITHOUT_ZOOKEEPER" && -z "$CLUSTER_UUID" ]]; then
echo "ERROR: missing CLUSTER_UUID when use KAFKA_WITHOUT_ZOOKEEPER"
exit 1
fi

if [[ -z "$KAFKA_PORT" ]]; then
export KAFKA_PORT=9092
fi
Expand Down Expand Up @@ -118,7 +123,7 @@ echo "" >> "$KAFKA_HOME/config/server.properties"

# Fixes #312
# KAFKA_VERSION + KAFKA_HOME + grep -rohe KAFKA[A-Z0-0_]* /opt/kafka/bin | sort | uniq | tr '\n' '|'
EXCLUSIONS="|KAFKA_VERSION|KAFKA_HOME|KAFKA_DEBUG|KAFKA_GC_LOG_OPTS|KAFKA_HEAP_OPTS|KAFKA_JMX_OPTS|KAFKA_JVM_PERFORMANCE_OPTS|KAFKA_LOG|KAFKA_OPTS|"
EXCLUSIONS="|KAFKA_VERSION|KAFKA_HOME|KAFKA_DEBUG|KAFKA_GC_LOG_OPTS|KAFKA_HEAP_OPTS|KAFKA_JMX_OPTS|KAFKA_JVM_PERFORMANCE_OPTS|KAFKA_LOG|KAFKA_OPTS|KAFKA_WITHOUT_ZOOKEEPER|"

# Read in env as a new-line separated array. This handles the case of env variables have spaces and/or carriage returns. See #313
IFS=$'\n'
Expand All @@ -132,7 +137,11 @@ echo "" >> "$KAFKA_HOME/config/server.properties"

if [[ $env_var =~ ^KAFKA_ ]]; then
kafka_name=$(echo "$env_var" | cut -d_ -f2- | tr '[:upper:]' '[:lower:]' | tr _ .)
updateConfig "$kafka_name" "${!env_var}" "$KAFKA_HOME/config/server.properties"
if [[ -z "$KAFKA_WITHOUT_ZOOKEEPER" ]]; then
updateConfig "$kafka_name" "${!env_var}" "$KAFKA_HOME/config/server.properties"
else
updateConfig "$kafka_name" "${!env_var}" "$KAFKA_HOME/config/kraft/server.properties"
fi
fi

if [[ $env_var =~ ^LOG4J_ ]]; then
Expand All @@ -146,4 +155,11 @@ if [[ -n "$CUSTOM_INIT_SCRIPT" ]] ; then
eval "$CUSTOM_INIT_SCRIPT"
fi

exec "$KAFKA_HOME/bin/kafka-server-start.sh" "$KAFKA_HOME/config/server.properties"
if [[ -z "$KAFKA_WITHOUT_ZOOKEEPER" ]]; then
exec "$KAFKA_HOME/bin/kafka-server-start.sh" "$KAFKA_HOME/config/server.properties"
elif [[ -d "/kafka/kafka-logs-kafka1" ]]; then
exec "$KAFKA_HOME/bin/kafka-server-start.sh" "$KAFKA_HOME/config/kraft/server.properties"
else
bash -c "$KAFKA_HOME/bin/kafka-storage.sh format -t $CLUSTER_UUID -c $KAFKA_HOME/config/kraft/server.properties"
exec "$KAFKA_HOME/bin/kafka-server-start.sh" "$KAFKA_HOME/config/kraft/server.properties"
fi