面向用户的服务的Istio请求路由不适用于入口网关

时间:2019-03-09 15:54:20

标签: kubernetes istio

我直接在Istio Ingress网关后面遇到Istio请求路由问题:

request routing

我有2个版本(v1,v2)的简单node.js应用程序(web-api),其中的Istio Ingress Gateway直接位于前面,并且Istio VirtualService应该在版本1和版本2之间进行80/20分发,但是没有。 Kiali显示了50/50的分布。

当我添加一个仅通过请求的简单前端服务时,一切都会按预期进行。 frontend added 根据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

1 个答案:

答案 0 :(得分: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