Skip to content

Instantly share code, notes, and snippets.

@bikram20
Last active June 6, 2021 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bikram20/0470dd3081cc0994526b83bf7f5bd2a5 to your computer and use it in GitHub Desktop.
Save bikram20/0470dd3081cc0994526b83bf7f5bd2a5 to your computer and use it in GitHub Desktop.
kind-kubernetes
# setup.sh
!/usr/bin/bash
kind create cluster --name cluster1 --config cluster1.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
kubectl create clusterrolebinding default-admin --clusterrole cluster-admin --serviceaccount=default:default
token=$(kubectl get secrets -o jsonpath="{.items[?(@.metadata.annotations['kubernetes\.io/service-account\.name']=='default')].data.token}"|base64 --decode)
echo "Cluster1 token:" $token
echo $token > cluster1.token
export PATH=$PWD/istio-1.6.2/bin:$PATH
istioctl install --set profile=demo
kubectl label namespace default istio-injection=enabled
# metallb
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.9.3/manifests/metallb.yaml
# On first install only
kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
kubectl apply -f cluster1.metallb
# bookinfo app
kubectl apply -f istio-1.6.2/samples/bookinfo/platform/kube/bookinfo.yaml
kubectl apply -f istio-1.6.2/samples/bookinfo/networking/bookinfo-gateway.yaml
exit
# Run manually
kubectl exec -it $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
#ports
export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].port}')
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
echo $GATEWAY_URL
echo http://$GATEWAY_URL/productpage
# Apply forwarding to all versions
kubectl apply -f istio-1.6.2/samples/bookinfo/networking/destination-rule-all.yaml
############## TRAFFIC MANAGEMENT ###############
### REQUEST ROUTING
# Verify that the ratings service change in the backend for every request.
# Route all traffic to v1
kubectl apply -f istio-1.6.2/samples/bookinfo/networking/virtual-service-all-v1.yaml
### ROUTE based on user identity
# Route user jason to v2 version
kubectl apply -f istio-1.6.2/samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
# WIP
# Config files
bikram@bikram-HP-Z820-Workstation:~/kind-clusters$ cat cluster1.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 32000
hostPort: 80
- role: worker
- role: worker
bikram@bikram-HP-Z820-Workstation:~/kind-clusters$ cat cluster1.metallb
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 172.18.255.1-172.18.255.100
bikram@bikram-HP-Z820-Workstation:~/kind-clusters$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment