Showcases Istio’s dynamic routing capabilities with a minimal set of example applications.
-
Openshift 3.9 cluster
-
Istio 0.7.1 with authentication installed on the aforementioned cluster. To install Istio simply follow one of the following docs:
-
Enable automatic sidecar injection for Istio
-
See this for details
-
-
Login to the cluster with the admin user
Note
|
The istiooc cluster up --istio=true command from this project perfectly satisfy the above requirements.
|
oc new-project istio-mutual-tls
CAUTION: In order for Istio automatic sidecar injection to work properly the following Istio configuration needs to be in place:
-
The
policy
field is set todisabled
in theistio-inject
configmap of theistio-system
namespace -
The
istio-sidecar-injector
MutatingWebhookConfiguration
should not limit the injection to properly labeled namespaces -
Expose services and Istio ingress
oc expose svc istio-ingress -n istio-system
The aforementioned configuration is not needed when the cluster has been setup using
istiooc
Execute the following command to build the project and deploy it to OpenShift:
mvn clean package fabric8:deploy -Popenshift
Configuration for FMP may be found both in pom.xml and src/main/fabric8
files/folders.
This configuration is used to define service names and deployments that control how pods are labeled/versioned on the OpenShift cluster. Labels and versions are key concepts for creating load-balanced or multi-versioned pods in a service.
Run the following commands to apply and execute the OpenShift templates that will configure and deploy the applications:
find . | grep openshiftio | grep application | xargs -n 1 oc apply -f
oc new-app --template=spring-boot-istio-ab-tests-booster-client-service-consumer -p SOURCE_REPOSITORY_URL=https://github.com/snowdrop/spring-boot-istio-ab-testing-booster -p SOURCE_REPOSITORY_REF=master -p SOURCE_REPOSITORY_DIR=client-service-consumer
oc new-app --template=spring-boot-istio-ab-tests-booster-service-a -p SOURCE_REPOSITORY_URL=https://github.com/snowdrop/spring-boot-istio-ab-testing-booster -p SOURCE_REPOSITORY_REF=master -p SOURCE_REPOSITORY_DIR=service-a
oc new-app --template=spring-boot-istio-ab-tests-booster-service-b -p SOURCE_REPOSITORY_URL=https://github.com/snowdrop/spring-boot-istio-ab-testing-booster -p SOURCE_REPOSITORY_REF=master -p SOURCE_REPOSITORY_DIR=service-b
-
Create a RouteRule to forward traffic to the demo application.
This is only necessary if your application accepts traffic at a different port/url than the default. In this case, our application accepts traffic at
/
, but we will access it with the path/example
.oc create -f rules/client-route-rule.yml
-
Access the application
Run the following command to determine the appropriate URL to access our demo. Make sure you access the url with the HTTP scheme. HTTPS is NOT enabled by default:
echo http://$(oc get route istio-ingress -o jsonpath='{.spec.host}{"\n"}' -n istio-system)/example/
The result of the above command is the istio-system istio-ingress URL, appended with the RouteRule path.
-
Access the application as described in the previous use case
-
Click "Invoke Service" in the client UI (Do this several times.)
-
Notice that the services are load-balanced at exactly 50%, which is the default cluster behavior.
-
-
Configure a load-balancing RouteRule Sometimes it is important to slowly direct traffic to a new service over time, or use alternate weighting. In this case, we will supply another Istio RouteRule to control load balancing behavior.
Run the following command:
oc create -f rules/ab-test-rule.yml
The RouteRule defined in the file above uses labels "a" and "b" to identify each unique version of the service. If multiple services match any of these labels, traffic will be divided between them accordingly. Additional routes/weights can be supplied using additional labels/service versions as desired.
-
Click "Invoke Service" in the client UI
Do this several times. You will notice that traffic is no longer routed at 50/50%, and more traffic is directed to service version B than service version A. Adjust the weights in the rule-file and re-run the command above. You should see traffic adjust accordingly.
NoteIt could take several seconds for the RouteRule to be detected and applied by Istio.
Congratulations! You now know how to direct traffic between different versions of a service using Istio RouteRules.