Istio Request Routing для пользовательской службы не работает с входным шлюзом - PullRequest
0 голосов
/ 09 марта 2019

У меня проблема с маршрутизацией запросов Istio непосредственно за входным шлюзом Istio:

request routing

У меня есть простое приложение node.js (web-api) в 2 версиях (v1, v2) с шлюзом Istio Ingress Gateway непосредственно во фронтальной части и Istio VirtualService, который должен выполнять распределение 80/20 между версиями 1 и 2, но это не так.Kiali показывает распределение 50/50.

Когда я добавляю простой сервис веб-интерфейса, который просто передает запрос, все работает, как и ожидалось.frontend added В соответствии с документацией Istio использование входа Istio позволяет запрашивать правила маршрутизации в пользовательских службах.Но для меня это не так, и я не понимаю, почему?

deploy.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

Ответы [ 2 ]

1 голос
/ 10 марта 2019

Вы должны присоединить виртуальную службу 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   
0 голосов
/ 11 марта 2019

С помощью Стефана я смог исправить это следующим образом:

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       
---

Теперь у меня есть правило входа (match / test) и маршрутизация запросов тоже работает правильно.

...