OpenShift 4 之Service Mesh教程(2)- 部署Istio的微服务

本部分会部署3个微服务,它们的关系如下图:Frontend_v1接收用户请求后会转发给后台Backend_v1和Backend_v2。
OpenShift 4 之Service Mesh教程(2)- 部署Istio的微服务_第1张图片

  1. 执行命令部署3个微服务和相关对象。在完成后可以看到3个运行的Pod,每个Pod中有2个Container(其中1个Container是自动注入的sidecar)。
$ oc apply -f ocp/backend-v1-deployment.yml -n my-istio-app
$ oc apply -f ocp/backend-v2-deployment.yml -n my-istio-app
$ oc apply -f ocp/backend-service.yml -n my-istio-app
$ oc apply -f ocp/frontend-v1-deployment.yml -n my-istio-app
$ oc apply -f ocp/frontend-service.yml -n my-istio-app
$ oc apply -f ocp/frontend-route.yml -n my-istio-app
$ oc get pod -n my-istio-app
NAME                          READY   STATUS    RESTARTS   AGE
backend-v1-6ddf9c7dcf-zmn4b   2/2     Running   0          12h
backend-v2-7655885b8c-qg4d7   2/2     Running   0          12h
frontend-v1-655f4478c-9dwnv   2/2     Running   0          12h
  1. 访问frontend微服务。backend-v1和backend-v2是被随机调用的,其中backend-v1用时较短,而backend-v2用时较长
$ export FRONTEND_URL=http://$(oc get route frontend -n my-istio-app -o jsonpath='{.status.ingress[0].host}')
$ curl $FRONTEND_URL -s -w "\nElapsed Time:%{time_total}\n"
Frontend version: v1 => [Backend: http://backend:8080, Response: 200, Body: Backend version:v1,Response:200,Host:backend-v1-6ddf9c7dcf-zmn4b, Message: Hello World!!]
Elapsed Time:1.236257
$ curl $FRONTEND_URL -s -w "\nElapsed Time:%{time_total}\n"
Frontend version: v1 => [Backend: http://backend:8080, Response: 200, Body: Backend version:v2,Response:200,Host:backend-v2-7655885b8c-qg4d7, Message: Hello World!!]
Elapsed Time:6.092146

你可能感兴趣的:(OpenShift,4,ServiceMesh,微服务)