本文部署Istio的实例BookInfo应用并配置访问路由等功能。在进行操作前,需先完成《OpenShift 4 之通过命令创建Service Mesh环境》。
$ BOOKINFO_PROJECT=bookinfo-red
$ oc new-project $BOOKINFO_PROJECT
$ ISTIO_RELEASE=$(curl --silent https://api.github.com/repos/istio/istio/releases/latest |grep -Po '"tag_name": "\K.*?(?=")')
$ oc get smmr default -n istio-system -o json --export | jq '.spec.members += ["'"$BOOKINFO_PROJECT"'"]' | oc apply -n istio-system -f -
$ oc get smmr default -n istio-system -o jsonpath={.spec.members}
[default bookinfo-red]
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/istio/istio/${ISTIO_RELEASE}/samples/bookinfo/platform/kube/bookinfo.yaml
for deployment in $(oc get deployments -o jsonpath='{.items[*].metadata.name}' -n $BOOKINFO_PROJECT);do
oc -n $BOOKINFO_PROJECT patch deployment $deployment -p '{"spec":{"template":{"metadata":{"annotations":{"sidecar.istio.io/inject": "true"}}}}}'
done
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/istio/istio/${ISTIO_RELEASE}/samples/bookinfo/networking/bookinfo-gateway.yaml
$ oc get gateway.networking.istio.io
NAME AGE
bookinfo-gateway 19m
$ GATEWAY_URL=$(oc -n istio-system get route istio-ingressgateway -o jsonpath='{.spec.host}')
$ while true; do curl -s http://${GATEWAY_URL}/productpage | grep -o ".* "; done
<title>Simple Bookstore App</title>
<title>Simple Bookstore App</title>
<title>Simple Bookstore App</title>
...
$ oc -n istio-system get route kiali -o jsonpath='{.spec.host}'
kiali-istio-system.apps-crc.testing
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/liuxiaoyu-git/redhat-service-mesh-demo/master/04-Dynamic-Routing/destination-rule-all.yaml
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/liuxiaoyu-git/redhat-service-mesh-demo/master/04-Dynamic-Routing/virtual-service-all-v1.yaml
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/liuxiaoyu-git/redhat-service-mesh-demo/master/04-Dynamic-Routing/virtual-service-reviews-80-20.yaml
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/liuxiaoyu-git/redhat-service-mesh-demo/master/04-Dynamic-Routing/virtual-service-reviews-v2.yaml
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/liuxiaoyu-git/redhat-service-mesh-demo/master/04-Dynamic-Routing/virtual-service-reviews-chrome.yaml
$ while true; do sleep 1; curl -A "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" -s http://${GATEWAY_URL}/productpage | grep -o "color=\"red\""; curl -s http://${GATEWAY_URL}/productpage | grep -o "color=\"black\"";done
oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/pichuang/redhat-service-mesh-demo/master/05-Traffic-Government/destination-rule-all.yaml
oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/pichuang/redhat-service-mesh-demo/master/05-Traffic-Government/virtual-service-reviews-all.yaml
2. 执行命令,将请求轮训发给reviews微服务的三个版本。
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/pichuang/redhat-service-mesh-demo/master/05-Traffic-Government/destination-rule-reviews-round-robin.yaml
3. 执行命令,将请求随机发给reviews微服务的三个版本。
$ oc apply -n $BOOKINFO_PROJECT -f https://raw.githubusercontent.com/pichuang/redhat-service-mesh-demo/master/05-Traffic-Government/destination-rule-reviews-random.yaml