Last active
September 20, 2020 12:21
-
-
Save nmittler/c7c8ee14db6923e7269690ac3f158f9c 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}" ) | |
HELLOWORLD_CTX="${ARGS[0]}" | |
OTHER_CTX="${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 createNamespace() | |
{ | |
for CTX in "${ARGS[@]}"; do | |
# Create the namespaces | |
kubectl create --context=${CTX} namespace sample | |
kubectl label --context=${CTX} namespace sample \ | |
istio-injection=enabled | |
done | |
} | |
function deploySleep() | |
{ | |
for CTX in "${ARGS[@]}"; do | |
# Deploy Sleep | |
kubectl apply --context=${CTX} \ | |
-f samples/sleep/sleep.yaml -n sample | |
done | |
} | |
function deployHelloWorldToFirstCluster() | |
{ | |
# Deploy HelloWorld Service | |
kubectl apply --context=${HELLOWORLD_CTX} \ | |
-f samples/helloworld/helloworld.yaml \ | |
-l app=helloworld -n sample | |
# Deploy HelloWorld version. | |
kubectl apply --context=${HELLOWORLD_CTX} \ | |
-f samples/helloworld/helloworld.yaml \ | |
-l app=helloworld -l version="v1" -n sample | |
} | |
function deployLocalServiceEntry() | |
{ | |
local IP=$(kubectl --context=$HELLOWORLD_CTX get svc helloworld -n sample -o jsonpath='{.spec.clusterIP}') | |
local PORT="5000" | |
deployServiceEntry $HELLOWORLD_CTX $IP $PORT | |
} | |
function deployRemoteServiceEntry() | |
{ | |
local IP=$(kubectl --context=$HELLOWORLD_CTX get svc --selector=app=istio-ingressgateway \ | |
-n istio-system -o jsonpath='{.items[0].status.loadBalancer.ingress[0].ip}') | |
local PORT="15443" | |
deployServiceEntry $OTHER_CTX $IP $PORT | |
} | |
function deployServiceEntry() | |
{ | |
local CTX=$1 | |
local IP=$2 | |
local PORT=$3 | |
# Deploy HelloWorld ServiceEntry for resolving .global. | |
kubectl apply --context=${CTX} -n sample -f - <<EOF | |
apiVersion: networking.istio.io/v1alpha3 | |
kind: ServiceEntry | |
metadata: | |
name: helloworld-global | |
spec: | |
hosts: | |
# must be of form name.namespace.global | |
- helloworld.sample.global | |
# Treat remote cluster services as part of the service mesh | |
# as all clusters in the service mesh share the same root of trust. | |
location: MESH_INTERNAL | |
ports: | |
- name: http | |
number: 5000 | |
protocol: http | |
resolution: DNS | |
addresses: | |
# the IP address to which httpbin.bar.global will resolve to | |
# must be unique for each remote service, within a given cluster. | |
# This address need not be routable. Traffic for this IP will be captured | |
# by the sidecar and routed appropriately. | |
- 240.0.0.2 | |
endpoints: | |
- address: ${IP} | |
ports: | |
http: ${PORT} | |
EOF | |
} | |
# Delete the namespace in all clusters | |
deleteNamespace | |
# Create the namespace in all clusters | |
createNamespace | |
# Deploy the sleep service to all clusters. | |
deploySleep | |
# Deploy the HelloWorld and sleep services to each cluster. | |
deployHelloWorldToFirstCluster | |
deployLocalServiceEntry | |
deployRemoteServiceEntry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment