Prerequisites:
- You will have OpenShift Service Mesh operator installed on OpenShift
- Installed Service Mesh
- Configure
addmissionConfig
to enable automatic sidecar injection. See more details here https://docs.openshift.com/container-platform/3.11/servicemesh-install/servicemesh-install.html#updating-master-configuration
When you have your OpenShift Service Mesh installed on your OpenShift Container Platform. You will clone this repo for the labs below.
-
Web UI
-
Grafanda: http://grafana-istio-system. Prometheus: http://prometheus-istio-system.
-
Customer metrics: cd ~/istio/istio-tutorial/ istioctl create -f istiofiles/recommendation_requestcount.yml -n istio-system cat istiofiles/recommendation_requestcount.yml
On Prometheus: istio_requests_total{destination_service="recommendation.demo.svc.cluster.local"}
-
show round robin for all pods
-
Apply all traffic to v1: oc apply -f virtual-service-all-v1.yaml -n bookinfo
-
Smart routing Route all to 50/50 v1&v3: oc replace -f virtual-service-reviews-50-v3.yaml
-
Apply user identity: oc replace -f virtual-service-reviews-jason-v2-v3.yaml -n bookinfo
oc replace -f virtual-service-reviews-90-10.yaml -n bookinfo
oc replace -f virtual-service-reviews-80-20.yaml -n bookinfo
oc replace -f virtual-service-reviews-10-90.yaml -n bookinfo
oc replace -f virtual-service-reviews-to-v2.yaml -n bookinfo
-
cd ../httpbin
-
Oc project httpbin
-
Run send traffic only to v1: ./route-rules-to-v1.sh sentTraffic.sh & versionV2logs.sh
-
Apply mirror virtual service rule
oc apply -f virtual-service-mirror.yaml -n httpbin
-
sentTraffic.sh & versionV2logs.sh
-
Cleanup bookinfo/review
-
Oc project bookinfo
-
Check the productpage is working around v1-v3
-
Cd ~/bookinfo
kubectl apply -f virtual-service-all-v1.yaml -n bookinfo
kubectl apply -f virtual-service-reviews-test-v2.yaml -n bookinfo
-
Login bookinfo app with user jason (no delay)
logout
kubectl apply -f virtual-service-ratings-test-delay.yaml -n bookinfo
Login bookinfo app with user jason (delay)
-
clean up:
kubectl delete -f virtual-service-ratings-test-delay.yaml -n bookinfo
kubectl delete -f virtual-service-reviews-test-v2.yaml -n bookinfo
kubectl delete -f virtual-service-all-v1.yaml -n bookinfo
-
Make sure rules are cleaned for bookinfo app
-
Oc project bookinfo
-
Check the productpage is working with v1-v3
-
Cd ~/bookinfo
kubectl apply -f virtual-service-all-v1.yaml
kubectl apply -f request-timeout-route-to-v2.yaml -n bookinfo
kubectl apply -f request-timeout-add-delay-to-rating.yaml -n bookinfo
-
load productpage and notice delay
kubectl apply -f request-timeout-add-timeout.yaml -n bookinfo
-
load productpage, returns in about 1 second, instead of 2, and the reviews are unavailable.
-
cleanup
kubectl delete -f virtual-service-all-v1.yaml -n bookinfo
-
oc project demo
-
V2 is a slower service
oc apply -f demo-destination-mtls.yaml -n demo
oc apply -f virtual-service-recommendation-v1_and_v2_50_50.yml -n demo
-
Run script ~/istio/istio-tutorial/scripts/cb1.sh >> see the v2 is slower
-
But suppose that in a production system this 3s delay was caused by too many concurrent requests to the same instance/pod. We don’t want multiple requests getting queued or making the instance/pod even slower. So we’ll add a circuit breaker that will open whenever we have more than 1 request being handled by any instance/pod.
oc replace -f destination-rule-recommendation_cb_policy_version_v2.yml -n demo
-
Run script ~/istio/istio-tutorial/scripts/cb1.sh You can run siege multiple times, but in all of the executions you should see some 503 errors being displayed in the results. That’s the circuit breaker being opened whenever Istio detects more than 1 pending request being handled by the instance/pod.
-
Clean up:
oc delete -f destination-rule-recommendation_cb_policy_version_v2.yml -n demo
oc delete -f virtual-service-recommendation-v1_and_v2_50_50.yml -n demo
Pool rejection
oc apply -f demo-destination-mtls.yaml -n demo
oc apply -f virtual-service-recommendation-v1_and_v2_50_50.yml -n demo
-
Scale up v2
oc scale dc recommendation-v2 --replicas=2 -n demo
-
Go to one of the pod terminal and type
curl localhost:8080/misbehave
-
Run script run-demo.sh >> 503 from miss behave pod
oc replace -f destination-rule-recommendation_cb_policy_pool_ejection.yml -n demo
-
Run script run-demo.sh >> less 503 error
-
Ultimate resilience with retries, circuit breaker, and pool ejection we can combine multiple Istio capabilities to achieve the ultimate backend resilience:
-
Circuit Breaker to avoid multiple concurrent requests to an instance;
-
Pool Ejection to remove failing instances from the pool of responding instances;
-
Retries to forward the request to another instance just in case we get an open circuit breaker and/or pool ejection;
By simply adding a retry configuration to our current virtualservice, we’ll be able to get rid completely of our 503
s requests.
oc replace -f virtual-service-recommendation-v1_and_v2_retry.yml -n demo
-
Run script run-demo.sh
-
cleanup
- Run the following commands to show the pods in each namespace
oc project test-mls
oc get pods -n foo
oc get pods -n bar
oc get pods -n legacy
kubectl exec $(kubectl get pod -l app=sleep -n bar -o jsonpath={.items..metadata.name}) -c sleep -n bar -- curl http://httpbin.foo:8000/ip -s -o /dev/null -w "%{http_code}\n"
for from in "foo" "bar" "legacy"; do for to in "foo" "bar" "legacy"; do kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} -- curl http://httpbin.${to}:8000/ip -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"; done; done
The non-Istio service, e.g sleep.legacy doesn’t have a sidecar, so it cannot initiate the required TLS connection to Istio services. As a result, requests from sleep.legacy to httpbin.foo or httpbin.bar will fail.
- Check out the MeshPolicy
oc get meshpolicy
oc get meshpolicy default -o yaml
This policy specifies that all workloads in the mesh will only accept encrypted requests using TLS. As you can see, this authentication policy has the kind: MeshPolicy. The name of the policy must be default, and it contains no targets specification (as it is intended to apply to all services in the mesh).
-
oc project egress
-
Web UI >> Egress project
-
Got to sleep pod terminal
curl http://httpbin.org/headers
curl https://www.google.com
time curl -o /dev/null -s -w "%{http_code}\n" http://httpbin.org/delay/5
-
Apply time out: ./set-timeout-to-external.sh
-
run: time curl -o /dev/null -s -w "%{http_code}\n" http://httpbin.org/delay/5