如何在 istio 虚拟服务中正确路由请求?

时间:2021-06-22 19:33:45

标签: kubernetes routes istio

我在 istio 上的 Minikube 中运行了以下服务。这些服务部署在启用 istio-injection 的默认命名空间中。

categories-api      ClusterIP   10.99.4.33       <none>        80/TCP    60m
justshop-api        ClusterIP   10.98.187.253    <none>        80/TCP    60m
manufacturers-api   ClusterIP   10.106.134.195   <none>        80/TCP    60m
products-api        ClusterIP   10.108.139.67    <none>        80/TCP    60m
reviews-api         ClusterIP   10.97.18.230     <none>        80/TCP    60m
taxes-api           ClusterIP   10.96.17.129     <none>        80/TCP    60m

从上述服务中,justshop-api 是从网关 80 端口接收流量的服务,然后根据指定的路径将流量路由到适当的服务

示例: http://:/products --- 此路由响应 200 ok http://:/products/10 --- 由于内部服务错误而失败。

与其他路线相同。

这是我的 yaml 文件

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: default-gateway
  namespace: istio-system
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: justshop-virtual-service
spec:
  hosts:
    - "*"
  gateways:
    - istio-system/default-gateway
  http:
  - route:
    - destination:
        host: justshop-api
          subset: v1
        weight: 100
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: justshop-destination-rule
spec:
  host: justshop-api
  subsets:
    - name: v1
      labels:
        version: v1.0.0

我在虚拟服务中尝试了使用前缀和正则表达式路径的各种组合。但没什么 作品。以上服务均在SpringBoot中开发。

有人可以帮我解决这个问题吗?

问候 拉杰

0 个答案:

没有答案