【问题标题】:Istio Request Routing for user-facing service doesn't work with ingress-gateway面向用户的服务的 Istio 请求路由不适用于 ingress-gateway
【发布时间】:2019-03-11 15:20:47
【问题描述】:

我在 Istio Ingress Gateway 后面遇到了 Istio 请求路由问题:

我有两个版本(v1、v2)的简单 node.js 应用程序(web-api),前面有一个 Istio Ingress Gateway,还有一个 Istio VirtualService,它应该在版本 1 和 2 之间进行 80/20 分布,但是它没有。 Kiali 显示出 50/50 的分布。

当我添加一个简单的前端服务来传递请求时,一切都按预期工作。 根据 Istio 文档,使用 Istio 入口允许在面向用户的服务中使用请求路由规则。但对我来说没有,我不明白为什么?

deployment.yaml:

apiVersion: apps/v1beta2 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: web-api-v1
spec:
  selector:
    matchLabels:
      app: web-api
      project: istio-test
      version: v1
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: web-api
        project: istio-test
        version: v1
    spec:
      containers:
      - image: web-api:1
        name: web-api-v1
        env:
        - name: VERS
          value: "=> Version 1"
        ports:
        - containerPort: 3000
          name: http
      restartPolicy: Always    
---
apiVersion: apps/v1beta2 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: web-api-v2
spec:
  selector:
    matchLabels:
      app: web-api
      project: istio-test
      version: v2
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: web-api
        project: istio-test
        version: v2
    spec:
      containers:
      - image: web-api:1
        name: web-api-v1
        env:
        - name: VERS
          value: "=> Version 2"
        ports:
        - containerPort: 3000
          name: http
      restartPolicy: Always    
---

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: web-api
  labels:
    app: web-api
    project: istio-test
spec:
  type: NodePort
  ports:
    - port: 3000  
      name: http
      protocol: TCP
  selector:
    app: web-api
---

istio-ingress.yaml:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: default-gateway-ingress
spec:
  selector:
    istio: ingressgateway # use Istio default gateway implementation
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
--- 
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: virtualservice-ingress
spec:
  hosts:
  - "*"
  gateways:
  - default-gateway-ingress
  http:
  - match:
    - uri:
        exact: /test
    route:
    - destination:
        host: web-api
        port:
          number: 3000
--- 

istio-virtualservice.yaml:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: web-api
spec:
  hosts:
  - web-api
  http:
  - route:
    - destination:
        host: web-api
        subset: v1
      weight: 80  
    - destination:
        host: web-api
        subset: v2 
      weight: 20   
---

我把这个例子放在https://github.com/Harald-U/istio-test

【问题讨论】:

    标签: kubernetes istio


    【解决方案1】:

    您必须将 web-api 虚拟服务附加到网关并删除 virtualservice-ingress 对象。

    以下是 web-api 虚拟服务的外观:

    apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: web-api
    spec:
      hosts:
      - "*"
      gateways:
      - default-gateway-ingress
      http:
      - route:
        - destination:
            host: web-api
            subset: v1
          weight: 80  
        - destination:
            host: web-api
            subset: v2 
          weight: 20   
    

    【讨论】:

      【解决方案2】:

      在 Stefans 的帮助下,我能够以这种方式修复它:

      apiVersion: networking.istio.io/v1alpha3
      kind: VirtualService
      metadata:
        name: virtualservice-ingress
      spec:
        hosts:
        - "*"
        gateways:
        - default-gateway-ingress
        http:
        - match:
          - uri:
              exact: /test
          route:
            - destination:
                host: web-api
                subset: v1
              weight: 80  
            - destination:
                host: web-api
                subset: v2 
              weight: 20       
      ---
      

      现在我有了入口规则(匹配/测试)并且请求路由也正常工作。

      【讨论】:

        猜你喜欢
        • 2020-06-11
        • 2019-09-06
        • 2020-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 2022-08-18
        • 2019-03-02
        相关资源
        最近更新 更多