Istio 流量管理 virtualservice(2)

http重写


重写就是当你去访问aa.rhce.cc/demo1它会帮你去转发到aa.rhce.cc/demo2上面,这个是地址的重写。

aa.rhce.cc/demo1 --->aa.rhce.cc/demo2

这个demo1路径和demo2路径是真实存在的,每个目录下面都有不同的静态文件。

# mkdir -p demo1
# mkdir -p demo2

# echo "demo1"  demo1/index.html
demo1 demo1/index.html
# echo "demo2" >demo2/index.html

# ls
50x.html  demo1  demo2	index.html
[root@k8s-master vs]# cat vsrewrite.yaml 
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: myvs
  namespace: istio
spec:
  hosts:
  - "cc.rhce.cc"
  gateways:
  - mygateway
  http:
  - name: aaa
    match:
    - uri:
        prefix: /demo1
    rewrite:
      uri: /demo2
    route:
    - destination:
        host: svc1
        port:
          number: 80

 访问:http://cc.rhce.cc:30744/demo1/index.html

 得到的结果是demo2。

转发到其他命名空间


这里如果不需要外界访问,那么就不需要创建gw了。

满足特定条件的时候,转发到 ns2 的svc1上

基于内容


不同的客户端访问同一个地址的时候,转发到不同的服务上面。其实也就是基于不同的客户端将用户的请求转发到不同的pod。 

下面就是请求报文的header里面是chrome那么转发到svc1,其他的情况转发到svc2。

猜你喜欢

转载自blog.csdn.net/qq_34556414/article/details/130483019