Skip to content

Instantly share code, notes, and snippets.

@lucasponce
Last active June 30, 2019 13:45
Show Gist options
  • Save lucasponce/282ed27b6baa5b506661b3e795f700aa to your computer and use it in GitHub Desktop.
Save lucasponce/282ed27b6baa5b506661b3e795f700aa to your computer and use it in GitHub Desktop.
Create a Kubernetes cluster using GKE and install Istio. Upgrade Kiali and install examples. Specific Linux comands to open browsers from command line
#!/bin/bash
echo "[1.0] Check pre-requisites"
# Check gcloud, kubectl, helm, istioctl, envsubst, curl commands
COMMANDS=(gcloud kubectl helm istioctl envsubst curl)
for CMD in "${COMMANDS[@]}"
do
which "$CMD" >/dev/null 2>&1
if [ ! "$?" == "0" ]; then
echo "$CMD command not found. Aborting installation."
exit 1
fi
done
# Check ISTIO_HOME
if [ -z "$ISTIO_HOME" ]; then
echo "ISTIO_HOME variable not set"
exit 1
fi
echo "[1.1] Create a Kubernetes cluster based on GKE"
CLUSTER_NAME=$1
if [ -z "$CLUSTER_NAME" ]; then
INSTALLER=$(basename "$0")
echo "Cluster name not passed as parameter. "
echo "i.e. ${INSTALLER} my-cluster"
exit 1
fi
gcloud container clusters create ${CLUSTER_NAME} \
--cluster-version latest \
--num-nodes 6
echo "[1.2] Retrieve cluster credentials"
gcloud container clusters get-credentials ${CLUSTER_NAME}
echo "[1.3] Grant cluster administrator (admin) permissions"
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole=cluster-admin \
--user=$(gcloud config get-value core/account)
echo "[1.4] Install Istio definitions"
cd $ISTIO_HOME
kubectl create namespace istio-system
helm template install/kubernetes/helm/istio-init --name istio-init --namespace istio-system | kubectl apply -f -
CRDS=0
for i in {1..30}
do
CRDS=$(kubectl get crds | grep 'istio.io\|certmanager.k8s.io' | wc -l)
if [ ! "$CRDS" == "53" ]; then
echo "[${i}] Waiting for CRDs..."
sleep 2
else
break
fi
done
if [ ! "$CRDS" == "53" ]; then
echo "CRDs have not been created. Aborting installation."
fi
echo "[1.5] Install Istio Demo profile"
helm template install/kubernetes/helm/istio --name istio --namespace istio-system \
--values install/kubernetes/helm/istio/values-istio-demo.yaml | kubectl apply -f -
kubectl get pods -n istio-system -w
echo "[1.6.0] Expose the telemetry add-ons"
curl -L https://git.io/fj2rL | kubectl apply -f -
export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export KIALI_URL="http://${INGRESS_HOST}:15029/kiali"
export PROMETHEUS_URL="http://${INGRESS_HOST}:15030/"
export GRAFANA_URL="http://${INGRESS_HOST}:15031/"
export JAEGER_URL="http://${INGRESS_HOST}:15032/jaeger"
echo "[1.6.1] Opening URLs"
echo "Warning, xdg-open is a Linux command"
xdg-open ${KIALI_URL} 2>&1 &
xdg-open ${PROMETHEUS_URL} 2>&1 &
xdg-open ${GRAFANA_URL} 2>&1 &
xdg-open ${JAEGER_URL} 2>&1 &
read -rsp $'Press enter to continue...\n'
echo "[1.7.0] Install bookinfo in default namespace"
kubectl label namespace default istio-injection=enabled
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
kubectl get pods -w
echo "[1.7.1] Expose bookinfo through Ingress"
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
xdg-open http://${INGRESS_HOST}:${INGRESS_PORT}/productpage 2>&1 &
read -rsp $'Press enter to continue...\n'
echo "[1.8.0] Upgrade Kiali"
curl -L https://git.io/fjohL | envsubst > $HOME/update-kiali-cr.yaml
bash <(curl -L https://git.io/getLatestKialiOperator) -oiv v1.0.0 --kiali-cr $HOME/update-kiali-cr.yaml
kubectl get pods -n istio-system -w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment