Skip to content

Commit de0919b

Browse files
authored
Merge pull request #78 from Yolean/outside-services
Outside (i.e. cluster-external) access through per-broker Service
2 parents 3fad8bf + 5f27972 commit de0919b

File tree

5 files changed

+71
-1
lines changed

5 files changed

+71
-1
lines changed

10broker-config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ data:
2222
else
2323
sed -i "s/#init#broker.rack=#init#/broker.rack=$ZONE/" /etc/kafka/server.properties
2424
fi
25+
26+
kubectl -n $POD_NAMESPACE label pod $POD_NAME kafka-broker-id=$KAFKA_BROKER_ID
27+
28+
OUTSIDE_HOST=$(kubectl get node "$NODE_NAME" -o jsonpath='{.status.addresses[?(@.type=="InternalIP")].address}')
29+
if [ $? -ne 0 ]; then
30+
echo "Outside (i.e. cluster-external access) host lookup command failed"
31+
else
32+
OUTSIDE_HOST=${OUTSIDE_HOST}:3240${KAFKA_BROKER_ID}
33+
sed -i "s|#init#advertised.listeners=OUTSIDE://#init#|advertised.listeners=OUTSIDE://${OUTSIDE_HOST}|" /etc/kafka/server.properties
34+
fi
2535
}
2636
2737
server.properties: |-
@@ -58,14 +68,18 @@ data:
5868
# EXAMPLE:
5969
# listeners = PLAINTEXT://your.host.name:9092
6070
#listeners=PLAINTEXT://:9092
71+
listeners=OUTSIDE://:9094,PLAINTEXT://:9092
6172
6273
# Hostname and port the broker will advertise to producers and consumers. If not set,
6374
# it uses the value for "listeners" if configured. Otherwise, it will use the value
6475
# returned from java.net.InetAddress.getCanonicalHostName().
6576
#advertised.listeners=PLAINTEXT://your.host.name:9092
77+
#init#advertised.listeners=OUTSIDE://#init#,PLAINTEXT://:9092
6678
6779
# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
6880
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
81+
listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL,OUTSIDE:PLAINTEXT
82+
inter.broker.listener.name=PLAINTEXT
6983
7084
# The number of threads that the server uses for receiving requests from the network and sending responses to the network
7185
num.network.threads=3

50kafka.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ spec:
2121
valueFrom:
2222
fieldRef:
2323
fieldPath: spec.nodeName
24+
- name: POD_NAME
25+
valueFrom:
26+
fieldRef:
27+
fieldPath: metadata.name
28+
- name: POD_NAMESPACE
29+
valueFrom:
30+
fieldRef:
31+
fieldPath: metadata.namespace
2432
command: ['/bin/bash', '/etc/kafka/init.sh']
2533
volumeMounts:
2634
- name: config
@@ -32,7 +40,10 @@ spec:
3240
- name: KAFKA_LOG4J_OPTS
3341
value: -Dlog4j.configuration=file:/etc/kafka/log4j.properties
3442
ports:
35-
- containerPort: 9092
43+
- name: inside
44+
containerPort: 9092
45+
- name: outside
46+
containerPort: 9094
3647
command:
3748
- ./bin/kafka-server-start.sh
3849
- /etc/kafka/server.properties

outside-services/outside-0.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: outside-0
5+
namespace: kafka
6+
spec:
7+
selector:
8+
app: kafka
9+
kafka-broker-id: "0"
10+
ports:
11+
- protocol: TCP
12+
targetPort: 9094
13+
port: 32400
14+
nodePort: 32400
15+
type: NodePort

outside-services/outside-1.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: outside-1
5+
namespace: kafka
6+
spec:
7+
selector:
8+
app: kafka
9+
kafka-broker-id: "1"
10+
ports:
11+
- protocol: TCP
12+
targetPort: 9094
13+
port: 32401
14+
nodePort: 32401
15+
type: NodePort

outside-services/outside-2.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: outside-2
5+
namespace: kafka
6+
spec:
7+
selector:
8+
app: kafka
9+
kafka-broker-id: "2"
10+
ports:
11+
- protocol: TCP
12+
targetPort: 9094
13+
port: 32402
14+
nodePort: 32402
15+
type: NodePort

0 commit comments

Comments
 (0)