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

Commit

Permalink
demo: Add scripts for Kafka demo (#4770)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
keithmattix authored Jun 7, 2022
1 parent 6045fb7 commit d3596c0
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 13 deletions.
94 changes: 94 additions & 0 deletions demo/deploy-kafka.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

set -aueo pipefail

# shellcheck disable=SC1091
source .env
DEPLOY_ON_OPENSHIFT="${DEPLOY_ON_OPENSHIFT:-false}"
USE_PRIVATE_REGISTRY="${USE_PRIVATE_REGISTRY:-false}"
MESH_NAME="${MESH_NAME:-osm}"

kubectl create ns kafka

bin/osm namespace add --mesh-name "$MESH_NAME" kafka

bin/osm metrics enable --namespace kafka

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}"

if [ "$DEPLOY_ON_OPENSHIFT" = true ] ; then
oc adm policy add-scc-to-user privileged -z "kafka" -n "kafka"
if [ "$USE_PRIVATE_REGISTRY" = true ]; then
oc secrets link "kafka" "$CTR_REGISTRY_CREDS_NAME" --for=pull -n "kafka"
fi
fi

kubectl apply -f - <<EOF
apiVersion: specs.smi-spec.io/v1alpha4
kind: TCPRoute
metadata:
name: kafka
namespace: kafka
spec:
matches:
ports:
- 9092
---
apiVersion: specs.smi-spec.io/v1alpha4
kind: TCPRoute
metadata:
name: kafka-internal
namespace: kafka
spec:
matches:
ports:
- 9092
- 9093
---
kind: TrafficTarget
apiVersion: access.smi-spec.io/v1alpha3
metadata:
name: kafka
namespace: kafka
spec:
destination:
kind: ServiceAccount
name: kafka
namespace: kafka
rules:
- kind: TCPRoute
name: kafka
sources:
- kind: ServiceAccount
name: default
namespace: kafka
---
kind: TrafficTarget
apiVersion: access.smi-spec.io/v1alpha3
metadata:
name: kafka-internal
namespace: kafka
spec:
destination:
kind: ServiceAccount
name: kafka
namespace: kafka
rules:
- kind: TCPRoute
name: kafka-internal
sources:
- kind: ServiceAccount
name: kafka
namespace: kafka
EOF

# Use these commands to test out Kafka
#
# Create and exec into a pod with a Kafka image
# kubectl run --rm -it kafka-client --image docker.io/bitnami/kafka:3.1.0-debian-10-r60 --namespace kafka -- bash
# Run the Kafka producer command (opens an interactive prompt where each line entered is sent as a Kafka message)
# You can exit the prompt with Ctrl-C
# kafka-console-producer.sh --broker-list kafka-0.kafka-headless.kafka.svc.cluster.local:9092 --topic test
# Now, run the Kafka consumer command (starts a loop to read messages from Kafka)
# You can exit the prompt with Ctrl-C
# kafka-console-consumer.sh --bootstrap-server kafka.kafka.svc.cluster.local:9092 --topic test --from-beginning
54 changes: 41 additions & 13 deletions demo/deploy-zookeeper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,31 @@ if [ "$DEPLOY_ON_OPENSHIFT" = true ] ; then
fi
fi

kubectl apply -nzookeeper -f - <<EOF
kubectl apply -f - <<EOF
apiVersion: specs.smi-spec.io/v1alpha4
kind: TCPRoute
metadata:
name: zookeeper
namespace: zookeeper
spec:
matches:
ports:
- 2181
- 3181
---
apiVersion: specs.smi-spec.io/v1alpha4
kind: TCPRoute
metadata:
name: zookeeper-internal
namespace: zookeeper
spec:
matches:
ports:
- 2181
- 3181
- 2888
- 3888
---
kind: TrafficTarget
apiVersion: access.smi-spec.io/v1alpha3
metadata:
Expand All @@ -40,21 +64,25 @@ spec:
name: zookeeper
sources:
- kind: ServiceAccount
name: zookeeper
namespace: zookeeper
name: kafka
namespace: kafka
---
apiVersion: specs.smi-spec.io/v1alpha4
kind: TCPRoute
kind: TrafficTarget
apiVersion: access.smi-spec.io/v1alpha3
metadata:
name: zookeeper
name: zookeeper-internal
namespace: zookeeper
spec:
matches:
ports:
- 2181
- 3181
- 2888
- 3888
destination:
kind: ServiceAccount
name: zookeeper
namespace: zookeeper
rules:
- kind: TCPRoute
name: zookeeper-internal
sources:
- kind: ServiceAccount
name: zookeeper
namespace: zookeeper
EOF

0 comments on commit d3596c0

Please sign in to comment.