istio kiali展示gRPC示例调用链

资源

https://it.baiked.com/kubernetes/3425.html

https://www.servicemesher.com/blog/istio-envoy-grpc-metrics-winning-with-service-mesh-in-practice/

使用docker部署grpc示例

构建grpc-servergrpc-client镜像

[root@vm02 grpc-test]# ls
client-0.0.1-SNAPSHOT.jar  grpc-client.yml  grpc-server.yml  server-0.0.1-SNAPSHOT.jar

[root@vm02 grpc-test]# cat grpc-server.yml 
FROM openjdk:8-jdk
COPY ./server-0.0.1-SNAPSHOT.jar /usr/local
EXPOSE 8001
ENTRYPOINT ["java", "-jar", "/usr/local/server-0.0.1-SNAPSHOT.jar"]

[root@vm02 grpc-test]# cat grpc-client.yml 
FROM openjdk:8-jdk
COPY ./client-0.0.1-SNAPSHOT.jar /usr/local
EXPOSE 8002
ENTRYPOINT ["java", "-jar", "/usr/local/client-0.0.1-SNAPSHOT.jar"]

docker build -t grpc-server:1.0 -f ./grpc-server.yml .
docker build -t grpc-client:1.0 -f ./grpc-client.yml .
docker run --name grpcserver -P -d grpc-server:1.0
docker run --name grpcclient -P --link grpcserver --env GRPC_ADDRESS=grpcserver -d grpc-client:1.0
[root@vm02 grpc-test]# curl localhost:32768/hello
this is grpc server!

[root@vm02 grpc-test]# curl localhost:32769/hello
this is grpc client!

[root@vm02 grpc-test]# curl localhost:32769/grpc
Hello wu jingang!

使用istio部署grpc示例

应用资源文件apps.yml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: grpcserver
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: grpcserver
        app: grpcserver
    spec:
      serviceAccountName: default
      containers:
      - name: grpcserver
        image: grpc-server:1.0
        ports:
        - containerPort: 8001
          name: http-port
        - containerPort: 5001
          name: grpc-port
---
apiVersion: v1
kind: Service
metadata:
  name: grpc-server-svc
spec:
  ports:
  - name: http
    port: 8001
    targetPort: 8001
  - name: grpc-port
    port: 5001
    targetPort: 5001
  selector:
    name: grpcserver
  type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: grpcclient
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: grpcclient
        app: grpcclient
    spec:
      serviceAccountName: default
      containers:
      - name: grpcclient
        image: grpc-client:1.0
        ports:
        - containerPort: 8002
          name: http-port
        env:
        - name: GRPC_ADDRESS
          value: grpc-server-svc
---
apiVersion: v1
kind: Service
metadata:
  name: grpc-client-svc
spec:
  ports:
    - name: http
      port: 8002
      targetPort: 8002
  selector:
    name: grpcclient
  type: NodePort

部署

[root@vm01 grpc-test]# kubectl create ns n2
namespace/n2 created
[root@vm01 grpc-test]# kubectl label ns n2 istio-injection=enabled
namespace/n2 labeled
[root@vm01 grpc-test]# kubectl apply -f apps.yml -n n2
deployment.extensions/grpcserver created
service/grpcserver created
deployment.extensions/grpcclient created
service/grpcclient created

[root@vm01 ~]# kubectl get po -n n2
NAME                         READY   STATUS    RESTARTS   AGE
grpcclient-89485c74c-258tz   2/2     Running   0          32s
grpcserver-b5b8d5964-jnjv5   2/2     Running   0          32s

# 端口转发kiali,使得虚拟机外可访问
[root@vm01 grpc-test]# kubectl -n istio-system port-forward --address 0.0.0.0 svc/kiali 20001:20001

测试

[root@vm01 grpc-test]# kubectl get svc -n n2
NAME              TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)                         AGE
grpc-client-svc   NodePort   10.1.116.151           8002:31148/TCP                  18m
grpc-server-svc   NodePort   10.1.132.57            8001:31462/TCP,5001:31926/TCP   18m

# 访问grpc client hello接口
[root@vm01 grpc-test]# curl http://192.168.11.11:31148/hello
this is grpc client!

# 访问grpc client grpc接口,内部使用gRPC调用grpc server
[root@vm01 grpc-test]# curl http://192.168.11.11:31148/grpc
Hello wu jingang!

# 访问grpc server hello接口
[root@vm01 grpc-test]# curl http://192.168.11.11:31462/hello
this is grpc server!

访问多次后生成的调用链图

istio kiali展示gRPC示例调用链_第1张图片
调用链

你可能感兴趣的:(istio kiali展示gRPC示例调用链)