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