Skip to content

Commit dd9ce95

Browse files
committed
Exemplifies external access using host lookup that works with minikube
Listener ports from https://hub.docker.com/r/wurstmeister/kafka/ Config based on KIP-103
1 parent c92d50c commit dd9ce95

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

10broker-config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ data:
2424
fi
2525
2626
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
2735
}
2836
2937
server.properties: |-
@@ -63,14 +71,18 @@ data:
6371
# EXAMPLE:
6472
# listeners = PLAINTEXT://your.host.name:9092
6573
#listeners=PLAINTEXT://:9092
74+
listeners=OUTSIDE://:9094,PLAINTEXT://:9092
6675
6776
# Hostname and port the broker will advertise to producers and consumers. If not set,
6877
# it uses the value for "listeners" if configured. Otherwise, it will use the value
6978
# returned from java.net.InetAddress.getCanonicalHostName().
7079
#advertised.listeners=PLAINTEXT://your.host.name:9092
80+
#init#advertised.listeners=OUTSIDE://#init#,PLAINTEXT://:9092
7181
7282
# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
7383
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
84+
listener.security.protocol.map=OUTSIDE:PLAINTEXT,PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL
85+
inter.broker.listener.name=PLAINTEXT
7486
7587
# The number of threads that the server uses for receiving requests from the network and sending responses to the network
7688
num.network.threads=3

50kafka.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ spec:
4141
value: -Dlog4j.configuration=file:/etc/kafka/log4j.properties
4242
ports:
4343
- containerPort: 9092
44+
- containerPort: 9094
4445
command:
4546
- ./bin/kafka-server-start.sh
4647
- /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)