如何使用ISTIO虚拟服务和网关路由两个GRPC服务

发布于 2025-02-04 17:19:04 字数 1410 浏览 3 评论 0原文

我的项目中有两个GRPC服务(GRPC-1& GRPC-2)。我已经在OpenShift的两个不同端口上部署了GRPC服务,并在Istio中创建了必要的配置,例如Gateway和Virtual Services。

我观察到,在任何时候,当我使用“/”到达服务路线时,只有一项GRPC服务被调用。我还尝试添加上下文路径,例如“/grpc-1”和“/grpc-2”,但它不起作用。

以下是我的代码段,来自Virtual Services和Gateway

grpc_gateway.yaml

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: grpc-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
    - port:
        name: http
        number: 80
        protocol: HTTP
      hosts:
        - "*"   

grpc-1-vs.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: grpc-1-vs
spec:
  hosts:
  - "istio-ingressgateway-istio-system.apps.xxxx.zfjb.p1.openshiftapps.com"
  gateways:
  - grpc-gateway
  http:
  - match:
    - uri:
        prefix: "/"
    route:
    - destination:
        port:
          number: 9014
        host: grpc-1

grpc-2-vs.yaml,

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: grpc-2-vs
spec:
  hosts:
  - "istio-ingressgateway-istio-system.apps.xxxx.zfjb.p1.openshiftapps.com"
  gateways:
  - grpc-gateway
  http:
  - match:
    - uri:
        prefix: "/"
    route:
    - destination:
        port:
          number: 9015
        host: grpc-2

我无法根据请求URL路由到两个GRPC服务。只有一项GRPC服务正在路由。

I have two grpc services (grpc-1 & grpc-2) in my project. I have deployed the grpc services on two different ports in openshift and created necessary configuration in Istio like gateway and virtual services.

I observed that at any time only one grpc service getting invoked as I am using "/" to route to services. I also tried to add context path like "/grpc-1" and "/grpc-2" but it didn't work.

Below is my code snippet from virtual services and gateway

grpc_gateway.yaml

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: grpc-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
    - port:
        name: http
        number: 80
        protocol: HTTP
      hosts:
        - "*"   

grpc-1-vs.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: grpc-1-vs
spec:
  hosts:
  - "istio-ingressgateway-istio-system.apps.xxxx.zfjb.p1.openshiftapps.com"
  gateways:
  - grpc-gateway
  http:
  - match:
    - uri:
        prefix: "/"
    route:
    - destination:
        port:
          number: 9014
        host: grpc-1

grpc-2-vs.yaml

apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: grpc-2-vs
spec:
  hosts:
  - "istio-ingressgateway-istio-system.apps.xxxx.zfjb.p1.openshiftapps.com"
  gateways:
  - grpc-gateway
  http:
  - match:
    - uri:
        prefix: "/"
    route:
    - destination:
        port:
          number: 9015
        host: grpc-2

I am not able to route to two grpc services based on request url. Only one grpc service is being routed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文