十三 Istio:Istio项目实际案例——Online Boutique( 五 )

现在我们将 VirtualService 配置为将所有进入的流量路由到 original 子集,我们可以安全地创建新的前端部署 。
[root@k8scloude1 ~]# vim frontend-v1.yaml[root@k8scloude1 ~]# cat frontend-v1.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: frontend-v1spec:selector:matchLabels:app: frontendversion: 1.0.0template:metadata:labels:app: frontendversion: 1.0.0annotations:sidecar.istio.io/rewriteAppHTTPProbers: "true"spec:containers:- name: serverimage: gcr.lank8s.cn/tetratelabs/boutique-frontend:1.0.0ports:- containerPort: 8080readinessProbe:initialDelaySeconds: 10httpGet:path: "/_healthz"port: 8080httpHeaders:- name: "Cookie"value: "shop_session-id=x-readiness-probe"livenessProbe:initialDelaySeconds: 10httpGet:path: "/_healthz"port: 8080httpHeaders:- name: "Cookie"value: "shop_session-id=x-liveness-probe"env:- name: PORTvalue: "8080"- name: PRODUCT_CATALOG_SERVICE_ADDRvalue: "productcatalogservice:3550"- name: CURRENCY_SERVICE_ADDRvalue: "currencyservice:7000"- name: CART_SERVICE_ADDRvalue: "cartservice:7070"- name: RECOMMENDATION_SERVICE_ADDRvalue: "recommendationservice:8080"- name: SHIPPING_SERVICE_ADDRvalue: "shippingservice:50051"- name: CHECKOUT_SERVICE_ADDRvalue: "checkoutservice:5050"- name: AD_SERVICE_ADDRvalue: "adservice:9555"- name: ENV_PLATFORMvalue: "gcp"resources:requests:cpu: 100mmemory: 64Milimits:cpu: 200mmemory: 128Mi创建前端部署frontend-v1
[root@k8scloude1 ~]# kubectl apply -f frontend-v1.yamldeployment.apps/frontend-v1 created#deploy正常运行[root@k8scloude1 ~]# kubectl get deploy | grep frontend-v1frontend-v11/11154s#pod正常运行[root@k8scloude1 ~]# kubectl get pod | grep frontend-v1frontend-v1-6457cb648d-fgmkk2/2Running070s如果我们在浏览器中打开 INGRESS_HOST , 我们仍然会看到原始版本的前端 。浏览器打开http://192.168.110.190/,显示的前端如下:

十三 Istio:Istio项目实际案例——Online Boutique

文章插图
让我们更新 VirtualService 中的权重 , 开始将 30% 的流量路由到 v1 的子集 。
[root@k8scloude1 ~]# vim frontend-30.yaml [root@k8scloude1 ~]# cat frontend-30.yamlapiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:name: frontend-ingressspec:hosts:- '*'gateways:- frontend-gatewayhttp:- route:- destination:host: frontend.online-boutique.svc.cluster.localport:number: 80subset: originalweight: 70- destination:host: frontend.online-boutique.svc.cluster.localport:number: 80subset: v1weight: 30更新 VirtualService
[root@k8scloude1 ~]# kubectl apply -f frontend-30.yamlvirtualservice.networking.istio.io/frontend-ingress configured[root@k8scloude1 ~]# kubectl get virtualservicesNAMEGATEWAYSHOSTSAGEfrontend["frontend.online-boutique.svc.cluster.local"]5d14hfrontend-ingress["frontend-gateway"]["*"]20m浏览器访问http://192.168.110.190/,查看前端界面 , 如果我们刷新几次网页 , 我们会注意到来自前端 v1 的更新标头,一般显示$75,如下所示:
十三 Istio:Istio项目实际案例——Online Boutique

文章插图
多刷新几次页面显示$30,如下所示:
十三 Istio:Istio项目实际案例——Online Boutique

文章插图
我们可以在浏览器中打开 http://192.168.110.130:30754,进入 kiali界面查看服务的拓扑结构,选择online-boutique命名空间,查看Graph
十三 Istio:Istio项目实际案例——Online Boutique

文章插图
服务的拓扑结构如下,我们会发现有两个版本的前端在运行:
十三 Istio:Istio项目实际案例——Online Boutique

文章插图
八.故障注入8.1 故障注入我们将为推荐服务引入 5 秒的延迟 。Envoy 将为 50% 的请求注入延迟 。
[root@k8scloude1 ~]# vim recommendation-delay.yaml[root@k8scloude1 ~]# cat recommendation-delay.yamlapiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:name: recommendationservicespec:hosts:- recommendationservice.online-boutique.svc.cluster.localhttp:- route:- destination:host: recommendationservice.online-boutique.svc.cluster.localfault:delay:percentage:value: 50fixedDelay: 5s将上述 YAML 保存为 recommendation-delay.yaml , 然后用 kubectl apply -f recommendation-delay.yaml 创建 VirtualService 。
[root@k8scloude1 ~]# kubectl apply -f recommendation-delay.yamlvirtualservice.networking.istio.io/recommendationservice created[root@k8scloude1 ~]# kubectl get virtualserviceNAMEGATEWAYSHOSTSAGEfrontend["frontend.online-boutique.svc.cluster.local"]6d13hfrontend-ingress["frontend-gateway"]["*"]23hrecommendationservice["recommendationservice.online-boutique.svc.cluster.local"]7s我们可以在浏览器中打开 INGRESS_HOST http://192.168.110.190/ , 然后点击其中一个产品 。推荐服务的结果显示在屏幕底部的”Other Products You Might Light“部分 。如果我们刷新几次页面 , 我们会注意到,该页面要么立即加载 , 要么有一个延迟加载页面 。这个延迟是由于我们注入了 5 秒的延迟 。

推荐阅读