记录一次在istio架构下的路径拦截重定向做法
目的实现总结
目的
想要对特定的URI路径进行拦截重新转发到新的路径下面
实现
istio提供了两种最基本的做法:HTTPRewrite和HTTPRedirect 关键配置如下:
HTTPRedirect:
http
:
- match
:
- uri
:
exact
: /v1
/getProductRatings
redirect
:
uri
: /v1
/bookRatings
HTTPRewrite:
http
:
- match
:
- uri
:
prefix
: /ratings
rewrite
:
uri
: /v1
/bookRatings
route
:
- destination
:
host
: ratings
.prod
.svc
.cluster
.local
subset
: v1
或
http
:
- match
:
- uri
:
exact
: /ratings
rewrite
:
uri
: /v1
/bookRatings
route
:
- destination
:
host
: ratings
.prod
.svc
.cluster
.local
subset
: v1
总结
两者都能达到重定向URI的功能,但是HTTPRedirect重定向方式不能与route共用,实际应用上个人更推荐HTTPRewrite