-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ads mode request routing and traffic_shifting
Signed-off-by: lec-bit <[email protected]>
- Loading branch information
Showing
2 changed files
with
366 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |