Dockerfile for Apache Kafka, fork of wurstmeister/kafka-docker.
It is transparently replaceable with its upstream, but based on Oracle Linux + GraalVM CE instead of Alphine Linux + Openjdk.
Since this project aims to create a Graalvm-equivalent for the upstream Docker image, it also follows the upstream project's tags. As of present, available tags are:
2.13-2.7.0
(graalvm ce 21.0.0-java8)2.13-2.6.0
(graalvm ce 21.0.0-java8)2.13-2.5.1
(graalvm ce 21.0.0-java8)
The following configuration shows how to configure a kafka cluster with this Docker image in Kubernetes cluster, with a Zookeeper cluster available in djlee-zookeeper-headless
service.
Note:
- For configuring Zookeeper cluster, see here.
- 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.
apiVersion: v1
kind: Service
metadata:
name: djlee-kafka-headless
labels:
app: djlee-kafka-headless
spec:
selector:
app: djlee-kafka
ports:
- port: 5555
name: jmi
- port: 9092
targetPort: 9092
name: kafka
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: djlee-kafka
labels:
app: djlee-kafka
spec:
selector:
matchLabels:
app: djlee-kafka
serviceName: djlee-kafka-headless
replicas: 4
template:
metadata:
name: djlee-kafka
labels:
app: djlee-kafka
spec:
initContainers:
containers:
- name: djlee-kafka
image: dongjinleekr/kafka:2.13-2.7.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9092
name: kafka
- containerPort: 5555
name: jmx
env:
- name: BROKER_ID_COMMAND
value: "[[ `hostname` =~ -([0-9]+) ]] && echo ${BASH_REMATCH[1]}"
- name: HOSTNAME_COMMAND
value: hostname
- name: KAFKA_LISTENERS
value: PLAINTEXT://:9092
- name: KAFKA_ADVERTISED_LISTENERS
value: PLAINTEXT://_{HOSTNAME_COMMAND}.djlee-kafka-headless:9092
- name: KAFKA_ZOOKEEPER_CONNECT
value: djlee-zookeeper-0.djlee-zookeeper-headless:2181,djlee-zookeeper-1.djlee-zookeeper-headless:2181/kafka
- name: KAFKA_LOG_DIRS
value: /kafka/kafka-logs
- name: KAFKA_JMX_PORT
value: "5555"
- name: KAFKA_CLEANUP_POLICY
value: "compact"
volumeMounts:
- name: kafka-storage
mountPath: /kafka
volumeClaimTemplates:
- metadata:
name: kafka-storage
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 50Mi
As you can see above, a environment variale named with KAFKA_A_B
corresponds to a configuration property of a.b
. For example, KAFKA_ADVERTISED_LISTENERS
corresponds to [advertised.listeners
property](](https://kafka.apache.org/documentation/#brokerconfigs_advertised.listeners) in Kafka Broker configuration).
To build the image yourself, run following:
SCALA_VERSION=2.13 KAFKA_VERSION=2.7.0 && docker build --build-arg scala_version=${SCALA_VERSION} --build-arg kafka_version=${KAFKA_VERSION} -t dongjinleekr/kafka:${SCALA_VERSION}-${KAFKA_VERSION} .