Open jvermillard opened 1 year ago
this was super helpful @jvermillard! This was my set-up for k8s in case someone else needs this also:
First a config-map:
apiVersion: v1
kind: ConfigMap
metadata:
name: kafka-start-config-script
data:
kafka_start.sh: |
#!/bin/sh
sed -i '/KAFKA_ZOOKEEPER_CONNECT/d' /etc/confluent/docker/configure
sed -i 's/cub zk-ready/echo ignore zk-ready/' /etc/confluent/docker/ensure
echo "kafka-storage format --ignore-formatted -t NqnEdODVKkiLTfJvqd1uqQ== -c /etc/kafka/kafka.properties" >> /etc/confluent/docker/ensure
/etc/confluent/docker/run
And deployment
:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: kafka
component: kafka-broker
name: kafka-broker
spec:
replicas: 1
selector:
matchLabels:
app: kafka
component: kafka-broker
template:
metadata:
labels:
app: kafka
component: kafka-broker
spec:
# otherwise we will get an env var "KAFKA_PORT" (from service name: "kafka" and appended with "_PORT")
# and this will cause this problem: https://github.com/confluentinc/cp-docker-images/blob/master/debian/kafka/include/etc/confluent/docker/configure#L58-L62
# Another solution is to rename the service.
enableServiceLinks: false
volumes:
- name: kafka-start-config-script
configMap:
name: kafka-start-config-script
defaultMode: 0744
containers:
- name: kafka-start-config-script
volumeMounts:
- name: kafka-start-config-script
mountPath: /tmp
command:
- /tmp/./kafka_start.sh
image: confluentinc/cp-kafka:7.2.1
ports:
- containerPort: 9092
env:
- name: KAFKA_BROKER_ID
value: "1"
- name: KAFKA_LISTENER_SECURITY_PROTOCOL_MAP
value: "CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT"
- name: KAFKA_ADVERTISED_LISTENERS
value: "PLAINTEXT://kafka:9092"
- name: KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR
value: "1"
- name: KAFKA_PROCESS_ROLES
value: "broker,controller"
- name: KAFKA_NODE_ID
value: "1"
- name: KAFKA_LISTENERS
value: "PLAINTEXT://:9092,CONTROLLER://:9093"
- name: KAFKA_INTER_BROKER_LISTENER_NAME
value: "PLAINTEXT"
- name: KAFKA_CONTROLLER_LISTENER_NAMES
value: "CONTROLLER"
- name: KAFKA_CONTROLLER_QUORUM_VOTERS
value: "1@localhost:9093"
Theind the new Krafis t mode super convenient for developer machines of CI because removing the second VM for ZK saves a lot of memory. Still, I found running it from your docker image pretty complicated.
After hours of internet search and experimentation, I ended up with this solution:
And the
run_workaround.sh
file contains the following:It would be nice if it were more straightforward (or a better method would be documented).