Created
August 6, 2020 19:30
-
-
Save nmittler/cdca9db77cfef663f79569de0213ae2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
ARGS=( "${@:1}" ) | |
function deleteNamespace() | |
{ | |
for CTX in "${ARGS[@]}"; do | |
# Delete the namespace if it already exists. | |
kubectl delete ns sample --context=${CTX} --ignore-not-found | |
done | |
} | |
function deployServices() | |
{ | |
for I in ${!ARGS[@]}; do | |
CTX=${ARGS[$I]} | |
# Toggle between v1 and v2. | |
VERSION_NUM=$(( $(( $I % 2 )) + 1)) | |
VERSION="v${VERSION_NUM}" | |
echo "Deploying version ${VERSION} to cluster ${CTX}" | |
# Create the namespaces | |
kubectl create --context=${CTX} namespace sample | |
kubectl label --context=${CTX} namespace sample \ | |
istio-injection=enabled | |
# Deploy HelloWorld Service | |
kubectl apply --context=${CTX} \ | |
-f ${ISTIO}/samples/helloworld/helloworld.yaml \ | |
-l app=helloworld -n sample | |
# Deploy HelloWorld version. | |
kubectl apply --context=${CTX} \ | |
-f ${ISTIO}/samples/helloworld/helloworld.yaml \ | |
-l app=helloworld -l version=${VERSION} -n sample | |
# Deploy Sleep | |
kubectl apply --context=${CTX} \ | |
-f ${ISTIO}/samples/sleep/sleep.yaml -n sample | |
done | |
} | |
function sendTraffic() | |
{ | |
for CTX in "${ARGS[@]}"; do | |
echo "Sending traffic from cluster $CTX" | |
for i in {1..10}; do | |
kubectl exec --context=${CTX} -it -n sample -c sleep \ | |
$(kubectl get pod --context=${CTX} -n sample -l \ | |
app=sleep -o jsonpath='{.items[0].metadata.name}') -- curl \ | |
helloworld.sample:5000/hello | |
done | |
done | |
} | |
# Delete the namespaces if they exist. | |
deleteNamespace | |
# Deploy the HelloWorld and sleep services to each cluster. | |
deployServices | |
# Sleep for a bit to wait for deployments. | |
echo "Waiting for ready..." | |
sleep 30 | |
# Send traffic from each cluster and log the version. | |
sendTraffic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment