From 287b98f21e580edd165f1a8c1e26e2be2d55b8e1 Mon Sep 17 00:00:00 2001 From: lec-bit Date: Tue, 9 Jul 2024 17:33:20 +0800 Subject: [PATCH] ads mode request routing and traffic_shifting Signed-off-by: lec-bit --- .../en/docs/userguide/request_routing_ads.md | 187 ++++++++++++++++++ .../en/docs/userguide/traffic_shifting_ads.md | 179 +++++++++++++++++ 2 files changed, 366 insertions(+) create mode 100644 content/en/docs/userguide/request_routing_ads.md create mode 100644 content/en/docs/userguide/traffic_shifting_ads.md diff --git a/content/en/docs/userguide/request_routing_ads.md b/content/en/docs/userguide/request_routing_ads.md new file mode 100644 index 0000000..ecc8c90 --- /dev/null +++ b/content/en/docs/userguide/request_routing_ads.md @@ -0,0 +1,187 @@ +--- +draft: false +linktitle: Request Routing +menu: + docs: + parent: user guide + weight: 2 +title: Request Routing +toc: true +type: docs + +--- + +This task shows you how to set up Request Routing policy for http traffic in Kmesh. + +### Before you begin + +- Install Kmesh + + Please refer [quickstart](https://kmesh.net/en/docs/setup/quickstart/) and change into ads mode + +- Deploy the fortio Applications + +```shell +kubectl apply -f samples/fortio/fortio-route.yaml +kubectl apply -f samples/fortio/netutils.yaml +``` + + +- Check app status and ensure that the service application is managed by Kmesh + + ```log + kubectl get pod + NAME READY STATUS RESTARTS AGE + fortio-v1-596b55cb8b-sfktr 1/1 Running 0 57m + fortio-v2-76997f99f4-qjsmd 1/1 Running 0 57m + netutils-575f5c569-lr98z 1/1 Running 0 67m + + kubectl describe pod netutils-575f5c569-lr98z | grep Annotations + Annotations: kmesh.net/redirection: enabled + ``` + +### Test the routing configuration + +- Display the defined routes with the following command: + + ```shell + $ kubectl get virtualservices -o yaml + apiVersion: v1 + items: + - apiVersion: networking.istio.io/v1beta1 + kind: VirtualService + metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"networking.istio.io/v1alpha3","kind":"VirtualService","metadata":{"annotations":{},"name":"fortio","namespace":"default"},"spec":{"hosts":["fortio"],"http":[{"route":[{"destination":{"host":"fortio","subset":"v1"},"weight":90},{"destination":{"host":"fortio","subset":"v2"},"weight":10}]}]}} + creationTimestamp: "2024-07-09T09:00:36Z" + generation: 1 + name: fortio + namespace: default + resourceVersion: "11166" + uid: 0a07f283-ac26-4d86-b3bd-ce6aa07dc628 + spec: + hosts: + - fortio + http: + - route: + - destination: + host: fortio + subset: v1 + weight: 90 + - destination: + host: fortio + subset: v2 + weight: 10 + kind: List + metadata: + resourceVersion: "" + ``` + + +- You have configured fortio 90% to route to the `v1` version of the fortio server + + ```log + $ for i in {1..20}; do kubectl exec -it $(kubectl get pod | grep netutils | awk '{print $1}') -- curl -v $(kubectl get svc -owide | grep fortio | awk '{print $3}'):80 | grep "Server:"; done + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 2 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 2 + < Server: 1 + < Server: 1 + ``` + + +## Route based on user identity + +- Next, you will change the route configuration so that all traffic from a specific user is routed to a specific service version. In this case, all traffic from a user named Jason will be routed to the service `fortio:v2`. + +- `kubectl apply -f samples/fortio/fortio-header.yaml` + + fortio-header.yaml + + ``` + apiVersion: networking.istio.io/v1alpha3 + kind: VirtualService + metadata: + name: fortio + spec: + hosts: + - fortio + http: + - match: + - headers: + end-user: + exact: jason + route: + - destination: + host: fortio + subset: v2 + - route: + - destination: + host: fortio + subset: v1 + ``` + +- Verify response from Server 1 + + ```shell + [root@localhost route]# for i in {1..10}; do kubectl exec -it $(kubectl get pod | grep netutils | awk '{print $1}') -- curl -v $(kubectl get svc -owide | grep fortio | awk '{print $3}'):80 | grep "Server:"; done + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + ``` + +- Verify response from Server 2 with header + + ```shell + [root@localhost route]# for i in {1..10}; do kubectl exec -it $(kubectl get pod | grep netutils | awk '{print $1}') -- curl \--header "end-user:jason" -v $(kubectl get svc -owide | grep fortio | awk '{print $3}'):80 | grep "Server:"; done + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + ``` + +### Understanding what happend + +If the user request header is not configured, V1 will be used. If the Jason request header is configured, V2 will be used. + +### Clean up + +1. Remove the application route rules + +``` +kubectl delete -f samples/fortio/fortio-route.yaml +kubectl delete -f samples/fortio/netutils.yaml +``` + +2. Remove kmesh + + Please refer [cleanup](https://kmesh.net/en/docs/setup/quickstart/#clean-up) diff --git a/content/en/docs/userguide/traffic_shifting_ads.md b/content/en/docs/userguide/traffic_shifting_ads.md new file mode 100644 index 0000000..9a92cf0 --- /dev/null +++ b/content/en/docs/userguide/traffic_shifting_ads.md @@ -0,0 +1,179 @@ +--- +draft: false +linktitle: Traffic Shifting +menu: + docs: + parent: user guide + weight: 2 +title: Traffic Shifting +toc: true +type: docs + + +--- + +This task shows you how to set up Traffic Shifting policy for http traffic in Kmesh. + +### Before you begin + +- Install Kmesh + + Please refer [quickstart](https://kmesh.net/en/docs/setup/quickstart/) and change into ads mode + +- Deploy the fortio Applications + +```shell +kubectl apply -f samples/fortio/fortio-route.yaml +kubectl apply -f samples/fortio/netutils.yaml +``` + + +- Check app status and ensure that the service application is managed by Kmesh + + ```log + kubectl get pod + NAME READY STATUS RESTARTS AGE + fortio-v1-596b55cb8b-sfktr 1/1 Running 0 57m + fortio-v2-76997f99f4-qjsmd 1/1 Running 0 57m + netutils-575f5c569-lr98z 1/1 Running 0 67m + + kubectl describe pod netutils-575f5c569-lr98z | grep Annotations + Annotations: kmesh.net/redirection: enabled + ``` + +### Test the routing configuration + +- Display the defined routes with the following command: + + ```shell + $ kubectl get virtualservices -o yaml + apiVersion: v1 + items: + - apiVersion: networking.istio.io/v1beta1 + kind: VirtualService + metadata: + annotations: + kubectl.kubernetes.io/last-applied-configuration: | + {"apiVersion":"networking.istio.io/v1alpha3","kind":"VirtualService","metadata":{"annotations":{},"name":"fortio","namespace":"default"},"spec":{"hosts":["fortio"],"http":[{"route":[{"destination":{"host":"fortio","subset":"v1"},"weight":90},{"destination":{"host":"fortio","subset":"v2"},"weight":10}]}]}} + creationTimestamp: "2024-07-09T09:00:36Z" + generation: 1 + name: fortio + namespace: default + resourceVersion: "11166" + uid: 0a07f283-ac26-4d86-b3bd-ce6aa07dc628 + spec: + hosts: + - fortio + http: + - route: + - destination: + host: fortio + subset: v1 + weight: 90 + - destination: + host: fortio + subset: v2 + weight: 10 + kind: List + metadata: + resourceVersion: "" + ``` + +- You have configured fortio 90% to route to the `v1` version of the fortio server + + ```log + $ for i in {1..20}; do kubectl exec -it $(kubectl get pod | grep netutils | awk '{print $1}') -- curl -v $(kubectl get svc -owide | grep fortio | awk '{print $3}'):80 | grep "Server:"; done + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 2 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 1 + < Server: 2 + < Server: 1 + < Server: 1 + ``` + +## Route based on user identity + +- Next, you will change the route configuration so that all traffic from a specific user is routed to a specific service version. In this case, all traffic from a user named Jason will be routed to the service `fortio:v2`. + +- `kubectl apply -f samples/fortio/fortio-v1-10-v2-90.yaml` + + fortio-header.yaml + + ``` + apiVersion: networking.istio.io/v1alpha3 + kind: VirtualService + metadata: + name: fortio + spec: + hosts: + - fortio + http: + - route: + - destination: + host: fortio + subset: v1 + weight: 10 + - destination: + host: fortio + subset: v2 + weight: 90 + ``` + +- Verify response from Server 1 + + ```shell + $ for i in {1..20}; do kubectl exec -it $(kubectl get pod | grep netutils | awk '{print $1}') -- curl -v $(kubectl get svc -owide | grep fortio | awk '{print $3}'):80 | grep "Server:"; done + < Server: 2 + < Server: 2 + < Server: 1 + < Server: 2 + < Server: 1 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 1 + < Server: 2 + < Server: 2 + < Server: 2 + < Server: 1 + < Server: 2 + < Server: 2 + < Server: 2 + ``` + +### Understanding what happend + +In this task you migrated traffic from an old to new version of the `fortio` service using kmesh’s weighted routing feature. + +With Kmesh, you can allow the two versions of the `fortio` service to scale up and down independently, without affecting the traffic distribution between them. + +### Clean up + +1. Remove the application route rules + +``` +kubectl delete -f samples/fortio/fortio-route.yaml +kubectl delete -f samples/fortio/netutils.yaml +``` + +2. Remove kmesh + + Please refer [cleanup](https://kmesh.net/en/docs/setup/quickstart/#clean-up) \ No newline at end of file