我按照本教程安装了 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
我更改了gateway
和VirtualService
部分中的hosts
字段,并在/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。我错过了什么?
PS:我正在使用istio1.0.5
您已经将路由设置为路径/productpage
,然后 您的VirtualService
中的 destination.host 应该与您的VirtualService
名称匹配,在您的情况下是"bookinfo">
然后运行 curl 命令
curl -I -HHost:bookinfo.com http://$INGRESS_HOST:$INGRESS_PORT/productpage
请注意,您可以使用 -H
标志将主机 HTTP 标头设置为"bookinfo.com"。这是必需的,因为入口网关配置为处理"bookinfo.com"。
如果您正在执行curl http://bookinfo.com/productpage
,则仅当您已完成该IP地址的主机文件条目时,它才有效。
或者更好的方法是在 curl 请求中显式发送标头:
curl <ip:port>/productpage --header 'Host: bookinfo.com'
如果你仍然做不到,现在就让我来。