我直接在Istio Ingress网关后面的Istio请求路由有问题:
我有两个版本(v1,v2)中的简单node.js应用程序(web-api),其中一个Istio Ingress Gateway直接位于一个Istio VirtualService,它应该在版本1和版本2之间进行80/20分配,但它没有'吨。 Kiali显示50/50分布。
当我添加一个只传递请求的简单前端服务时,一切都按预期工作。 根据Istio文档,使用Istio ingress允许在面向用户的服务中使用请求路由规则。但对我来说它没有,我不明白为什么?
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
---
Istion-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
---
Istion-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
---
您必须将web-api虚拟服务附加到网关并删除虚拟服务入口对象。
以下是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
借助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
---
现在我有入口规则(匹配/测试),请求路由也正常工作。