Istio traffic management virtualservice (2)

http rewrite


Rewriting means that when you visit aa.rhce.cc/demo1, it will forward it to aa.rhce.cc/demo2 for you. This is the rewriting of the address.

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

The demo1 path and demo2 path are real, and there are different static files under each directory.

# 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

 Visit: http://cc.rhce.cc:30744/demo1/index.html

 The result obtained is demo2.

Forward to other namespaces


If no external access is required here, then there is no need to create gw.

When certain conditions are met, it is forwarded to svc1 of ns2

content based


When different clients access the same address, they are forwarded to different services. In fact, it means forwarding user requests to different pods based on different clients. 

The following is that the header of the request message is chrome, then it is forwarded to svc1, and in other cases, it is forwarded to svc2.

Guess you like

Origin blog.csdn.net/qq_34556414/article/details/130483019