使用istio虚拟服务暴露3条路由
Use istio virtual service to expose 3 routes
我们现在切换到 istio,我需要将我的应用程序暴露给外部
在应用程序中,我只有 3 条路线
- "/" root route
- "/login"
- "static" - my app should serve some static files
我们有 gw
和 host
但不知何故我无法访问我的应用程序,知道我在这里做错了什么吗?
vs-yaml
有没有办法公开所有路由,或者我应该明确定义它们,如果是的话,怎么会有点混淆 routes
和 match
?
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bher-virtualservice
namespace: ba-trail
spec:
gateways:
- webb-system.svc.cluster.local
hosts:
- trialio.cloud.str
http:
- route:
- destination:
host: bsa
port:
number: 5000
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bher-virtualservice
namespace: ba-trail
spec:
gateways:
- webb-system.svc.cluster.local. #### don't look right , can write the gateway name only here. ####
hosts:
- trialio.cloud.str
http:
- route:
- destination:
host: bsa
port:
number: 5000 ## is your service working on this port
- rewrite: #### this should not be an issue but you can try adding this too
uri: /
if so how as it a bit confusing with routes and match
我建议看一下关于 virtual services 的 istio 文档,那里有很好的描述。
让我们从头说起,你有虚拟服务和网关,它们应该与你的应用程序在同一个命名空间中,或者你需要在两者中指定。
据我所知,您的虚拟服务不正确,我已经准备了适合您的示例。看看下面的例子。
网关
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bher-gateway
namespace: ba-trail
spec:
selector:
istio: ingressgateway # use the default IngressGateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "trialio.cloud.str"
我看到你已经部署了 gateway,如果它与虚拟服务不在同一个命名空间中,你应该像下面的例子一样添加它。
检查 spec.gateways
部分
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: my-gateway
namespace: some-config-namespace
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo-Mongo
namespace: bookinfo-namespace
spec:
gateways:
- some-config-namespace/my-gateway # can omit the namespace if gateway is in same
namespace as virtual service.
虚拟服务
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bher-virtualservice
namespace: ba-trail
spec:
gateways:
- bher-gateway // name of your gateway
hosts:
- trialio.cloud.str
http:
- match:
- uri:
prefix: "/"
- uri:
prefix: "/login"
- uri:
prefix: "/static"
- uri:
regex: '^.*\.(ico|png|jpg)$'
route:
- destination:
host: bsa.ba-trail.svc.cluster.local // name_of_your service.namespace.svc.cluster.local
port:
number: 5000
看看这个example
Let’s break down the requests that should be routed to Frontend:
Exact path / should be routed to Frontend to get the Index.html
Prefix path /static/* should be routed to Frontend to get any static files needed by the frontend, like Cascading Style Sheets and JavaScript files.
Paths matching the regex ^.*.(ico|png|jpg)$ should be routed to Frontend as it is an image, that the page needs to show.
http:
- match:
- uri:
exact: /
- uri:
exact: /callback
- uri:
prefix: /static
- uri:
regex: '^.*\.(ico|png|jpg)$'
route:
- destination:
host: frontend
port:
number: 80
希望您觉得这很有用。如果您有任何问题,请在评论中告诉我。
我们现在切换到 istio,我需要将我的应用程序暴露给外部
在应用程序中,我只有 3 条路线
- "/" root route
- "/login"
- "static" - my app should serve some static files
我们有 gw
和 host
但不知何故我无法访问我的应用程序,知道我在这里做错了什么吗?
vs-yaml
有没有办法公开所有路由,或者我应该明确定义它们,如果是的话,怎么会有点混淆 routes
和 match
?
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bher-virtualservice
namespace: ba-trail
spec:
gateways:
- webb-system.svc.cluster.local
hosts:
- trialio.cloud.str
http:
- route:
- destination:
host: bsa
port:
number: 5000
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bher-virtualservice
namespace: ba-trail
spec:
gateways:
- webb-system.svc.cluster.local. #### don't look right , can write the gateway name only here. ####
hosts:
- trialio.cloud.str
http:
- route:
- destination:
host: bsa
port:
number: 5000 ## is your service working on this port
- rewrite: #### this should not be an issue but you can try adding this too
uri: /
if so how as it a bit confusing with routes and match
我建议看一下关于 virtual services 的 istio 文档,那里有很好的描述。
让我们从头说起,你有虚拟服务和网关,它们应该与你的应用程序在同一个命名空间中,或者你需要在两者中指定。
据我所知,您的虚拟服务不正确,我已经准备了适合您的示例。看看下面的例子。
网关
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bher-gateway
namespace: ba-trail
spec:
selector:
istio: ingressgateway # use the default IngressGateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "trialio.cloud.str"
我看到你已经部署了 gateway,如果它与虚拟服务不在同一个命名空间中,你应该像下面的例子一样添加它。
检查 spec.gateways
部分
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: my-gateway
namespace: some-config-namespace
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo-Mongo
namespace: bookinfo-namespace
spec:
gateways:
- some-config-namespace/my-gateway # can omit the namespace if gateway is in same
namespace as virtual service.
虚拟服务
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bher-virtualservice
namespace: ba-trail
spec:
gateways:
- bher-gateway // name of your gateway
hosts:
- trialio.cloud.str
http:
- match:
- uri:
prefix: "/"
- uri:
prefix: "/login"
- uri:
prefix: "/static"
- uri:
regex: '^.*\.(ico|png|jpg)$'
route:
- destination:
host: bsa.ba-trail.svc.cluster.local // name_of_your service.namespace.svc.cluster.local
port:
number: 5000
看看这个example
Let’s break down the requests that should be routed to Frontend:
Exact path / should be routed to Frontend to get the Index.html
Prefix path /static/* should be routed to Frontend to get any static files needed by the frontend, like Cascading Style Sheets and JavaScript files.
Paths matching the regex ^.*.(ico|png|jpg)$ should be routed to Frontend as it is an image, that the page needs to show.
http:
- match:
- uri:
exact: /
- uri:
exact: /callback
- uri:
prefix: /static
- uri:
regex: '^.*\.(ico|png|jpg)$'
route:
- destination:
host: frontend
port:
number: 80
希望您觉得这很有用。如果您有任何问题,请在评论中告诉我。