After installing Istio1.8 on the aforementioned K8S cluster and configuring the cluster, demonstrate the first classic example Istio/Bookinfo application.
1. Application introduction
The Bookinfo application is divided into four separate microservices:
- Productpage. This microservice calls the Details and Reviews microservices to generate the page.
- This microservice contains information about books.
- Reviews. This micro-service contains book related reviews. It also invokes the Ratings microservice.
- Ratings this micro service contains rating information consisting of book reviews.
Reviews Microservices comes in 3 versions:
- The V1 version does not invoke the ratings service.
- The V2 version invokes the ratings service and uses one to five black star ICONS to display the rating information.
- The V3 version invokes the ratings service and uses 1 to 5 red star ICONS to display the rating information.
Several microservices in the Bookinfo app are written in different languages. These services are not dependent on Istio, but constitute a typical example of a service grid: it consists of multiple services, multiple languages, and multiple versions of the Reviews service.
2. Prepare the environment
Nodes of the domain name | role | IP |
---|---|---|
kmaster.local.com | master | 192.168.8.121 |
Windows
C:\Windows\System32\drivers\etc\hosts
Kmaster.local.com 192.168.8.121
Centos
$ echoKmaster.local.com 192.168.8.121 > > / etc/hostsCopy the code
3. Start the Istio Bookinfo deployment
3.1 Accessing the ISTIO Installation Directory
$ cd /usr/local/ istio -, version 1.8.1 /Copy the code
3.2 Enabling Static Side-car Injection
Istio automatically injects Sidecar by default.
$ kubectl label namespace default istio-injection=enabled
Copy the code
3.3 Installing Components
Istio -, version 1.8.1]# kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
service/details created
serviceaccount/bookinfo-details created
deployment.apps/details-v1 created
service/ratings created
serviceaccount/bookinfo-ratings created
deployment.apps/ratings-v1 created
service/reviews created
serviceaccount/bookinfo-reviews created
deployment.apps/reviews-v1 created
deployment.apps/reviews-v2 created
deployment.apps/reviews-v3 created
service/productpage created
serviceaccount/bookinfo-productpage created
deployment.apps/productpage-v1 created
Copy the code
The above command starts all four services, including the three versions of the Reviews service (V1, v2, and V3). In a real deployment, the microservice version starts over a period of time, not at the same time.
3.4 Verify that all services and PODS are correctly defined and started:
$kubectl get services NAME TYPE cluster-ip external-ip PORT(S) AGE Details ClusterIP 10.110.213.183 < None > 9080/TCP 3m39s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 17d productPage ClusterIP 10.105.81.93 < None > 9080/TCP 3M38s ratings Reviews ClusterIP 10.108.169.202 < None > 9080/TCP 3m39s Reviews ClusterIP 10.107.62.95 <none> 9080/TCP 3m38sCopy the code
There are
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
details-v1-79c697d759-5shh5 2/2 Running 0 5m42s
productpage-v1-65576bb7bf-s5psx 2/2 Running 0 5m41s
ratings-v1-7d99676f7f-5d4x6 2/2 Running 0 5m42s
reviews-v1-987d495c-wlhpl 2/2 Running 0 5m42s
reviews-v2-6c5bf657cf-rdttt 2/2 Running 0 5m42s
reviews-v3-5f7b9f4f77-rdd52 2/2 Running 0 5m42s
Copy the code
3.5 Confirming service startup
$ 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>"
<title>Simple Bookstore App</title>
Copy the code
3.6 Starting and exposing services
Istio -, version 1.8.1]# kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created
Copy the code
3.7 View the Exposed port corresponding to 80
Make it clear that your Kubernetes cluster environment supports external load balancing
$ kubectl get svc istio-ingressgateway -n istio-system
Copy the code
External exposed port: 32550 or view exposed port by following:
$ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
$ echo $INGRESS_PORT
32550
Copy the code
4 View the Bookinfo application
The browser input – kmaster.local.com: 32550 / productpage
4.1 Initial Visit
4.2 Refresh again or F5
4.3 Refresh again or F5
The problem is that the demo changes to a different version each time it is refreshed; How do I distribute to different versions
5 Establish a route distribution rule
5.1 Viewing subsets of all services,label corresponding to the LABEL defined by POD (mostly empty)
kubectl get destinationrules -o yaml
apiVersion: v1
items: []
kind: List
metadata:
resourceVersion: ""
selfLink: ""
Copy the code
5.2 Establishing a Route Distribution rule
Istio -, version 1.8.1]# kubectl apply -f samples/bookinfo/networking/destination-rule-all.yamldestinationrule.networking.istio.io/productpage created destinationrule.networking.istio.io/reviews created Destinationrule.net working. Istio. IO/ratings created destinationrule.net working. Istio. IO/details created istio -, version 1.8.1]# kubectl get destinationrules -o yaml
Copy the code
5.2.1 Complete to version V1
Istio -, version 1.8.1]# kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
virtualservice.networking.istio.io/productpage created
virtualservice.networking.istio.io/reviews created
virtualservice.networking.istio.io/ratings created
virtualservice.networking.istio.io/details created
Copy the code
virtual-service-all-v1.yaml
.
- route:
- destination:
host: productpage/reviews/ratings/details # Pay attention to the shorthand
subset: v1
.
Copy the code
At this point, no matter how to refresh the screen, will be positioned on the V1 version
5.2.2 User Jason routes to V2
Istio -, version 1.8.1]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml
virtualservice.networking.istio.io/reviews configured
Copy the code
At this point, no matter how to refresh the screen, json will be located on the V2 version
5.2.3 Routing the admin user to the V3 service
Istio -, version 1.8.1]# cp samples/bookinfo/networking/virtual-service-reviews-test-v2.yaml samples/bookinfo/networking/virtual-service-reviews-test-v3.yamlIstio -, version 1.8.1]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v3.yaml
virtualservice.networking.istio.io/reviews configured
Copy the code
Revised:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- match:
- headers:
end-user:
exact: admin
route:
- destination:
host: reviews
subset: v3
- route:
- destination:
host: reviews
subset: v1
Copy the code
Effective change
Istio -, version 1.8.1]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-test-v3.yaml
virtualservice.networking.istio.io/reviews configured
Copy the code
At this time, no matter how to refresh the screen, Admin will locate the V3 version
5.2.4 Version V1: V2 is distributed in a ratio of 80:20
Look at the virtual – service – reviews – 80-20. Yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v1
weight: 80
- destination:
host: reviews
subset: v2
weight: 20
Copy the code
Let’s make it efficient
Istio -, version 1.8.1]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-80-20.yaml
virtualservice.networking.istio.io/reviews configured
Copy the code
Look at the effect. Out of 10 flushes (request operations), only 2 are located to V2, and most are located to V1
5.2.5 Version V1: V2 is distributed in a ratio of 90:10
Look at the virtual – service – reviews – 90-10. Yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v1
weight: 90
- destination:
host: reviews
subset: v2
weight: 10
Copy the code
Let’s make it efficient
Istio -, version 1.8.1]# kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-90-10.yaml
virtualservice.networking.istio.io/reviews configured
Copy the code
So if you look at the effect at this point, one out of 10 requests is going to v2, which is pretty good.
Imagine if you were to increase the traffic allocation for V1 and decrease the traffic allocation for V2