Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit d3596c0

Browse files
authored
demo: Add scripts for Kafka demo (#4770)
* demo: Add scripts for Kafka demo Adding Kafka to our existing Zookeeper demo script makes the demo more relevant to our customers as Zookeeper is rarely used as a standalone datastore. This allows us to integrate Kafka into our demo if we wish (e.g. send a message every time a book is purchased) Signed-off-by: Keith Mattix II <[email protected]> * Address PR comment Signed-off-by: Keith Mattix II <[email protected]> * Add descriptive comments for Kafka demo commands Signed-off-by: Keith Mattix II <[email protected]> * Trigger E2E tests again Signed-off-by: Keith Mattix II <[email protected]>
1 parent 6045fb7 commit d3596c0

File tree

2 files changed

+135
-13
lines changed

2 files changed

+135
-13
lines changed

demo/deploy-kafka.sh

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/bash
2+
3+
set -aueo pipefail
4+
5+
# shellcheck disable=SC1091
6+
source .env
7+
DEPLOY_ON_OPENSHIFT="${DEPLOY_ON_OPENSHIFT:-false}"
8+
USE_PRIVATE_REGISTRY="${USE_PRIVATE_REGISTRY:-false}"
9+
MESH_NAME="${MESH_NAME:-osm}"
10+
11+
kubectl create ns kafka
12+
13+
bin/osm namespace add --mesh-name "$MESH_NAME" kafka
14+
15+
bin/osm metrics enable --namespace kafka
16+
17+
helm install kafka bitnami/kafka --set replicaCount=3 --set zookeeper.enabled=false --set zookeeperChrootPath='/kafka-root' --set serviceAccount.create=true --set serviceAccount.name=kafka --namespace kafka --set "externalZookeeper.servers={kafka-zookeeper-0.kafka-zookeeper-headless.zookeeper.svc.cluster.local,kafka-zookeeper-1.kafka-zookeeper-headless.zookeeper.svc.cluster.local,kafka-zookeeper-2.kafka-zookeeper-headless.zookeeper.svc.cluster.local}"
18+
19+
if [ "$DEPLOY_ON_OPENSHIFT" = true ] ; then
20+
oc adm policy add-scc-to-user privileged -z "kafka" -n "kafka"
21+
if [ "$USE_PRIVATE_REGISTRY" = true ]; then
22+
oc secrets link "kafka" "$CTR_REGISTRY_CREDS_NAME" --for=pull -n "kafka"
23+
fi
24+
fi
25+
26+
kubectl apply -f - <<EOF
27+
apiVersion: specs.smi-spec.io/v1alpha4
28+
kind: TCPRoute
29+
metadata:
30+
name: kafka
31+
namespace: kafka
32+
spec:
33+
matches:
34+
ports:
35+
- 9092
36+
---
37+
apiVersion: specs.smi-spec.io/v1alpha4
38+
kind: TCPRoute
39+
metadata:
40+
name: kafka-internal
41+
namespace: kafka
42+
spec:
43+
matches:
44+
ports:
45+
- 9092
46+
- 9093
47+
---
48+
kind: TrafficTarget
49+
apiVersion: access.smi-spec.io/v1alpha3
50+
metadata:
51+
name: kafka
52+
namespace: kafka
53+
spec:
54+
destination:
55+
kind: ServiceAccount
56+
name: kafka
57+
namespace: kafka
58+
rules:
59+
- kind: TCPRoute
60+
name: kafka
61+
sources:
62+
- kind: ServiceAccount
63+
name: default
64+
namespace: kafka
65+
---
66+
kind: TrafficTarget
67+
apiVersion: access.smi-spec.io/v1alpha3
68+
metadata:
69+
name: kafka-internal
70+
namespace: kafka
71+
spec:
72+
destination:
73+
kind: ServiceAccount
74+
name: kafka
75+
namespace: kafka
76+
rules:
77+
- kind: TCPRoute
78+
name: kafka-internal
79+
sources:
80+
- kind: ServiceAccount
81+
name: kafka
82+
namespace: kafka
83+
EOF
84+
85+
# Use these commands to test out Kafka
86+
#
87+
# Create and exec into a pod with a Kafka image
88+
# kubectl run --rm -it kafka-client --image docker.io/bitnami/kafka:3.1.0-debian-10-r60 --namespace kafka -- bash
89+
# Run the Kafka producer command (opens an interactive prompt where each line entered is sent as a Kafka message)
90+
# You can exit the prompt with Ctrl-C
91+
# kafka-console-producer.sh --broker-list kafka-0.kafka-headless.kafka.svc.cluster.local:9092 --topic test
92+
# Now, run the Kafka consumer command (starts a loop to read messages from Kafka)
93+
# You can exit the prompt with Ctrl-C
94+
# kafka-console-consumer.sh --bootstrap-server kafka.kafka.svc.cluster.local:9092 --topic test --from-beginning

demo/deploy-zookeeper.sh

+41-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,31 @@ if [ "$DEPLOY_ON_OPENSHIFT" = true ] ; then
2424
fi
2525
fi
2626

27-
kubectl apply -nzookeeper -f - <<EOF
27+
kubectl apply -f - <<EOF
28+
apiVersion: specs.smi-spec.io/v1alpha4
29+
kind: TCPRoute
30+
metadata:
31+
name: zookeeper
32+
namespace: zookeeper
33+
spec:
34+
matches:
35+
ports:
36+
- 2181
37+
- 3181
38+
---
39+
apiVersion: specs.smi-spec.io/v1alpha4
40+
kind: TCPRoute
41+
metadata:
42+
name: zookeeper-internal
43+
namespace: zookeeper
44+
spec:
45+
matches:
46+
ports:
47+
- 2181
48+
- 3181
49+
- 2888
50+
- 3888
51+
---
2852
kind: TrafficTarget
2953
apiVersion: access.smi-spec.io/v1alpha3
3054
metadata:
@@ -40,21 +64,25 @@ spec:
4064
name: zookeeper
4165
sources:
4266
- kind: ServiceAccount
43-
name: zookeeper
44-
namespace: zookeeper
67+
name: kafka
68+
namespace: kafka
4569
---
46-
apiVersion: specs.smi-spec.io/v1alpha4
47-
kind: TCPRoute
70+
kind: TrafficTarget
71+
apiVersion: access.smi-spec.io/v1alpha3
4872
metadata:
49-
name: zookeeper
73+
name: zookeeper-internal
5074
namespace: zookeeper
5175
spec:
52-
matches:
53-
ports:
54-
- 2181
55-
- 3181
56-
- 2888
57-
- 3888
58-
76+
destination:
77+
kind: ServiceAccount
78+
name: zookeeper
79+
namespace: zookeeper
80+
rules:
81+
- kind: TCPRoute
82+
name: zookeeper-internal
83+
sources:
84+
- kind: ServiceAccount
85+
name: zookeeper
86+
namespace: zookeeper
5987
EOF
6088

0 commit comments

Comments
 (0)