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

Use init container for per-pod config #47

Merged
merged 8 commits into from
Jul 27, 2017
9 changes: 8 additions & 1 deletion 10broker-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ metadata:
namespace: kafka
apiVersion: v1
data:
init.sh: |-
#!/bin/bash
set -x

export KAFKA_BROKER_ID=${HOSTNAME##*-}
sed -i "s/\${KAFKA_BROKER_ID}/$KAFKA_BROKER_ID/" /etc/kafka/server.properties

server.properties: |-
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
Expand All @@ -25,7 +32,7 @@ data:
############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
broker.id=${KAFKA_BROKER_ID}

# Switch to enable topic deletion or not, default value is false
#delete.topic.enable=true
Expand Down
31 changes: 19 additions & 12 deletions 50kafka.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ spec:
prometheus.io/port: "5556"
spec:
terminationGracePeriodSeconds: 30
initContainers:
- name: init-config
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
command: ['/bin/bash', '/etc/kafka/init.sh']
volumeMounts:
- name: config
mountPath: /etc/kafka
containers:
- name: metrics
image: solsson/kafka-prometheus-jmx-exporter@sha256:1f7c96c287a2dbec1d909cd8f96c0656310239b55a9a90d7fd12c81f384f1f7d
Expand All @@ -31,22 +38,22 @@ spec:
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
env:
- name: KAFKA_LOG4J_OPTS
value: -Dlog4j.configuration=file:/opt/kafka/config/log4j.properties
value: -Dlog4j.configuration=file:/etc/kafka/log4j.properties
- name: JMX_PORT
value: "5555"
ports:
- containerPort: 9092
command:
- /bin/sh
- -c
- >
./bin/kafka-server-start.sh
./config/server.properties
--override zookeeper.connect=zookeeper:2181
--override log.retention.hours=-1
--override log.dirs=/var/lib/kafka/data/topics
--override broker.id=${HOSTNAME##*-}
--override auto.create.topics.enable=false
- ./bin/kafka-server-start.sh
- /etc/kafka/server.properties
- --override
- zookeeper.connect=zookeeper:2181
- --override
- log.retention.hours=-1
- --override
- log.dirs=/var/lib/kafka/data/topics
- --override
- auto.create.topics.enable=false
resources:
requests:
cpu: 100m
Expand All @@ -59,7 +66,7 @@ spec:
- 'echo "" | nc -w 1 127.0.0.1 9092'
volumeMounts:
- name: config
mountPath: /opt/kafka/config
mountPath: /etc/kafka
- name: data
mountPath: /var/lib/kafka/data
volumes:
Expand Down
15 changes: 14 additions & 1 deletion zookeeper/10zookeeper-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ metadata:
namespace: kafka
apiVersion: v1
data:
init.sh: |-
#!/bin/bash
set -x

[ -z "$ID_OFFSET" ] && ID_OFFSET=1
export ZOOKEEPER_SERVER_ID=$((${HOSTNAME##*-} + $ID_OFFSET))
echo "${ZOOKEEPER_SERVER_ID:-1}" | tee /var/lib/zookeeper/data/myid
sed -i "s/server\.$ZOOKEEPER_SERVER_ID\=[a-z0-9.-]*/server.$ZOOKEEPER_SERVER_ID=0.0.0.0/" /etc/kafka/zookeeper.properties

zookeeper.properties: |-
tickTime=2000
dataDir=/var/lib/zookeeper/data
Expand All @@ -16,9 +25,13 @@ data:
server.3=pzoo-2.pzoo:2888:3888:participant
server.4=zoo-0.zoo:2888:3888:participant
server.5=zoo-1.zoo:2888:3888:participant

log4j.properties: |-
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%d] %p %m (%c)%n

# Suppress connection log messages, three lines per livenessProbe execution
log4j.logger.org.apache.zookeeper.server.NIOServerCnxnFactory=WARN
log4j.logger.org.apache.zookeeper.server.NIOServerCnxn=WARN
23 changes: 13 additions & 10 deletions zookeeper/50pzoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ spec:
prometheus.io/port: "5556"
spec:
terminationGracePeriodSeconds: 10
initContainers:
- name: init-config
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
command: ['/bin/bash', '/etc/kafka/init.sh']
volumeMounts:
- name: config
mountPath: /etc/kafka
- name: data
mountPath: /var/lib/zookeeper/data
containers:
- name: metrics
image: solsson/kafka-prometheus-jmx-exporter@sha256:1f7c96c287a2dbec1d909cd8f96c0656310239b55a9a90d7fd12c81f384f1f7d
Expand All @@ -40,18 +49,12 @@ spec:
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
env:
- name: KAFKA_LOG4J_OPTS
value: -Dlog4j.configuration=file:/opt/kafka/config/log4j.properties
value: -Dlog4j.configuration=file:/etc/kafka/log4j.properties
- name: JMX_PORT
value: "5555"
command:
- /bin/sh
- -euc
- >
export ZOOKEEPER_SERVER_ID=$((${HOSTNAME##*-} + 1));
echo "${ZOOKEEPER_SERVER_ID:-1}" | tee /var/lib/zookeeper/data/myid;
sed -i "s/server\.$ZOOKEEPER_SERVER_ID\=[a-z0-9.-]*/server.$ZOOKEEPER_SERVER_ID=0.0.0.0/" config/zookeeper.properties;
cat config/zookeeper.properties;
./bin/zookeeper-server-start.sh config/zookeeper.properties
- ./bin/zookeeper-server-start.sh
- /etc/kafka/zookeeper.properties
ports:
- containerPort: 2181
name: client
Expand All @@ -77,7 +80,7 @@ spec:
- '[ "imok" = "$(echo ruok | nc -w 1 127.0.0.1 2181)" ]'
volumeMounts:
- name: config
mountPath: /opt/kafka/config
mountPath: /etc/kafka
- name: data
mountPath: /var/lib/zookeeper/data
volumes:
Expand Down
26 changes: 16 additions & 10 deletions zookeeper/51zoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ spec:
prometheus.io/port: "5556"
spec:
terminationGracePeriodSeconds: 10
initContainers:
- name: init-config
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
command: ['/bin/bash', '/etc/kafka/init.sh']
env:
- name: ID_OFFSET
value: "4"
volumeMounts:
- name: config
mountPath: /etc/kafka
- name: data
mountPath: /var/lib/zookeeper/data
containers:
- name: metrics
image: solsson/kafka-prometheus-jmx-exporter@sha256:1f7c96c287a2dbec1d909cd8f96c0656310239b55a9a90d7fd12c81f384f1f7d
Expand All @@ -40,18 +52,12 @@ spec:
image: solsson/kafka:0.11.0.0@sha256:b27560de08d30ebf96d12e74f80afcaca503ad4ca3103e63b1fd43a2e4c976ce
env:
- name: KAFKA_LOG4J_OPTS
value: -Dlog4j.configuration=file:/opt/kafka/config/log4j.properties
value: -Dlog4j.configuration=file:/etc/kafka/log4j.properties
- name: JMX_PORT
value: "5555"
command:
- /bin/sh
- -euc
- >
export ZOOKEEPER_SERVER_ID=$((${HOSTNAME##*-} + 4));
echo "${ZOOKEEPER_SERVER_ID:-1}" | tee /var/lib/zookeeper/data/myid;
sed -i "s/server\.$ZOOKEEPER_SERVER_ID\=[a-z0-9.-]*/server.$ZOOKEEPER_SERVER_ID=0.0.0.0/" config/zookeeper.properties;
cat config/zookeeper.properties;
./bin/zookeeper-server-start.sh config/zookeeper.properties
- ./bin/zookeeper-server-start.sh
- /etc/kafka/zookeeper.properties
ports:
- containerPort: 2181
name: client
Expand All @@ -77,7 +83,7 @@ spec:
- '[ "imok" = "$(echo ruok | nc -w 1 127.0.0.1 2181)" ]'
volumeMounts:
- name: config
mountPath: /opt/kafka/config
mountPath: /etc/kafka
- name: data
mountPath: /var/lib/zookeeper/data
volumes:
Expand Down