google-kubernetes-engine - 主机匹配在 istio 网关中不起作用
问题描述
我按照本教程安装了 istio 并部署了示例bookinfo
应用程序。
他们有以下ingress-gateway.yml
文件
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "*"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080
当我这样做时kubectl apply -f ingress-gateway.yml
,它工作得很好,我可以访问应用程序http://<ip>/productpage
但是,如果我想在特定域上访问它,例如bookinfo.com
我更改了and部分hosts
中的字段,并在我的文件中添加了一个条目。gateway
VirtualService
/etc/hosts
于是,改成了下面这样
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "bookinfo.com"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "bookinfo.com"
gateways:
- bookinfo-gateway
http:
- match:
- uri:
exact: /productpage
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage
port:
number: 9080
当我尝试访问http://bookinfo.com/productpage
时,它给出了 404 not found。我错过了什么?
PS:我正在使用istio1.0.5
解决方案
您已经将路由设置为 path /productpage
,那么您的 destination.host 在您的情况下VirtualService
应该与您的VirtualService
姓名匹配,即“bookinfo”
然后运行 curl 命令
curl -I -HHost:bookinfo.com http://$INGRESS_HOST:$INGRESS_PORT/productpage
请注意,您使用该-H
标志将主机 HTTP 标头设置为“bookinfo.com”。这是必需的,因为您的入口网关配置为处理“bookinfo.com”。
推荐阅读
- python - 如何计算某一天停车场的占用率?
- batch-file - 如何在任何目录中的任何计算机上使用批处理文件
- python-3.x - 从 docker 执行 bash 脚本
- python - ImageGrab.grab(bbox) 没有抓取正确的尺寸。我正确使用 bbox 吗?
- node.js - 无法使用 mongoose 在 nodejs 应用程序中获取 mongodb 集合,使用 MongoClient 通过 aws lambda 函数插入
- python - cython 中的函数更改 numpy 数组类型
- python - 在 Python 中定义具有自动生成的 __init__ 和来自值字典的附加 init2 的数据类的正确方法是什么
- python - PyKalman 的 EM 算法和 AR(I)MA 状态空间方程
- php - 在处理另一个异常时,我应该如何处理记录器抛出的异常?
- laravel - 无法从模型加载信息,错误:找不到驱动程序