mirror of https://github.com/istio/istio.io.git
gateway-api: add gateway api instructions to traffic shifting task (#12213)
* gateway-api: add gateway api instructions to traffic shifting task * fixes * verify lines * fix request * more delay * disable flaky mirroring test
This commit is contained in:
parent
dff84b7fa2
commit
2f5744b92b
|
@ -6,9 +6,9 @@
|
|||
|
||||
Note that this document uses the Gateway API to configure internal mesh (east-west) traffic,
|
||||
i.e., not just ingress (north-south) traffic.
|
||||
Configuring internal mesh traffic using the Gateway API is an
|
||||
Configuring internal mesh traffic is an
|
||||
[experimental feature](https://gateway-api.sigs.k8s.io/concepts/versioning/#release-channels-eg-experimental-standard)
|
||||
currently under development and pending [upstream agreement](https://gateway-api.sigs.k8s.io/contributing/gamma/).
|
||||
of the Gateway API, currently under development and pending [upstream agreement](https://gateway-api.sigs.k8s.io/contributing/gamma/).
|
||||
Make sure to install the experimental CRDs before using the Gateway API:
|
||||
|
||||
{{< text syntax=bash snip_id=install_experimental_crds >}}
|
||||
|
|
|
@ -42,7 +42,7 @@ _wait_for_deployment default sleep
|
|||
|
||||
if [ "$GATEWAY_API" == "true" ]; then
|
||||
snip_creating_a_default_routing_policy_2
|
||||
sleep 10s # TODO proper wait
|
||||
sleep 30s # TODO proper wait
|
||||
else
|
||||
snip_creating_a_default_routing_policy_1
|
||||
|
||||
|
@ -59,7 +59,7 @@ _verify_not_contains snip_creating_a_default_routing_policy_5 "GET /headers HTTP
|
|||
|
||||
if [ "$GATEWAY_API" == "true" ]; then
|
||||
snip_mirroring_traffic_to_v2_2
|
||||
sleep 10s # TODO proper wait
|
||||
sleep 30s # TODO proper wait
|
||||
else
|
||||
snip_mirroring_traffic_to_v2_1
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck disable=SC1090,SC2154
|
||||
|
||||
# Copyright Istio Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
source "tests/util/gateway-api.sh"
|
||||
install_gateway_api_crds
|
||||
|
||||
# @setup profile=default
|
||||
source "content/en/docs/tasks/traffic-management/traffic-shifting/test.sh"
|
||||
|
||||
# @cleanup
|
||||
source "tests/util/samples.sh"
|
||||
snip_gtw_cleanup
|
||||
cleanup_bookinfo_sample
|
||||
cleanup_sleep_sample
|
||||
remove_gateway_api_crds
|
|
@ -18,6 +18,8 @@ from one destination to another.
|
|||
In this task, you will use send 50% of traffic to `reviews:v1` and 50% to `reviews:v3`. Then, you will
|
||||
complete the migration by sending 100% of traffic to `reviews:v3`.
|
||||
|
||||
{{< boilerplate gateway-api-gamma-support >}}
|
||||
|
||||
## Before you begin
|
||||
|
||||
* Setup Istio by following the instructions in the
|
||||
|
@ -30,17 +32,32 @@ complete the migration by sending 100% of traffic to `reviews:v3`.
|
|||
## Apply weight-based routing
|
||||
|
||||
{{< warning >}}
|
||||
If you haven't already applied destination rules, follow the instructions in [Apply Default Destination Rules](/docs/examples/bookinfo/#apply-default-destination-rules).
|
||||
If you haven't already, follow the instructions in [define the service versions](/docs/examples/bookinfo/#define-the-service-versions).
|
||||
{{< /warning >}}
|
||||
|
||||
1. To get started, run this command to route all traffic to the `v1` version of
|
||||
each microservice.
|
||||
1. To get started, run this command to route all traffic to the `v1` version:
|
||||
|
||||
{{< text syntax=bash snip_id=config_all_v1 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-all-v1.yaml@
|
||||
{{< /text >}}
|
||||
{{< tabset category-name="config-api" >}}
|
||||
|
||||
1. Open the Bookinfo site in your browser. The URL is `http://$GATEWAY_URL/productpage`, where `$GATEWAY_URL` is the External IP address of the ingress, as explained in
|
||||
{{< tab name="Istio classic" category-value="istio-classic" >}}
|
||||
|
||||
{{< text syntax=bash snip_id=config_all_v1 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-all-v1.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< tab name="Gateway API" category-value="gateway-api" >}}
|
||||
|
||||
{{< text syntax=bash snip_id=gtw_config_all_v1 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/gateway-api/route-reviews-v1.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< /tabset >}}
|
||||
|
||||
2) Open the Bookinfo site in your browser. The URL is `http://$GATEWAY_URL/productpage`, where `$GATEWAY_URL` is the External IP address of the ingress, as explained in
|
||||
the [Bookinfo](/docs/examples/bookinfo/#determine-the-ingress-ip-and-port) doc.
|
||||
|
||||
Notice that the reviews part of the page displays with no rating stars, no
|
||||
|
@ -48,37 +65,103 @@ the [Bookinfo](/docs/examples/bookinfo/#determine-the-ingress-ip-and-port) doc.
|
|||
all traffic for the reviews service to the version `reviews:v1` and this
|
||||
version of the service does not access the star ratings service.
|
||||
|
||||
1. Transfer 50% of the traffic from `reviews:v1` to `reviews:v3` with the following command:
|
||||
3) Transfer 50% of the traffic from `reviews:v1` to `reviews:v3` with the following command:
|
||||
|
||||
{{< text syntax=bash snip_id=config_50_v3 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-reviews-50-v3.yaml@
|
||||
{{< /text >}}
|
||||
{{< tabset category-name="config-api" >}}
|
||||
|
||||
Wait a few seconds for the new rules to propagate.
|
||||
{{< tab name="Istio classic" category-value="istio-classic" >}}
|
||||
|
||||
1. Confirm the rule was replaced:
|
||||
{{< text syntax=bash snip_id=config_50_v3 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-reviews-50-v3.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
{{< text syntax=bash outputis=yaml snip_id=verify_config_50_v3 >}}
|
||||
$ kubectl get virtualservice reviews -o yaml
|
||||
apiVersion: networking.istio.io/v1beta1
|
||||
kind: VirtualService
|
||||
...
|
||||
spec:
|
||||
hosts:
|
||||
- reviews
|
||||
http:
|
||||
- route:
|
||||
- destination:
|
||||
host: reviews
|
||||
subset: v1
|
||||
weight: 50
|
||||
- destination:
|
||||
host: reviews
|
||||
subset: v3
|
||||
weight: 50
|
||||
{{< /text >}}
|
||||
{{< /tab >}}
|
||||
|
||||
1. Refresh the `/productpage` in your browser and you now see *red* colored star ratings approximately 50% of the time. This is because the `v3` version of `reviews` accesses
|
||||
{{< tab name="Gateway API" category-value="gateway-api" >}}
|
||||
|
||||
{{< text syntax=bash snip_id=gtw_config_50_v3 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/gateway-api/route-reviews-50-v3.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< /tabset >}}
|
||||
|
||||
4) Wait a few seconds for the new rules to propagate and then
|
||||
confirm the rule was replaced:
|
||||
|
||||
{{< tabset category-name="config-api" >}}
|
||||
|
||||
{{< tab name="Istio classic" category-value="istio-classic" >}}
|
||||
|
||||
{{< text syntax=bash outputis=yaml snip_id=verify_config_50_v3 >}}
|
||||
$ kubectl get virtualservice reviews -o yaml
|
||||
apiVersion: networking.istio.io/v1beta1
|
||||
kind: VirtualService
|
||||
...
|
||||
spec:
|
||||
hosts:
|
||||
- reviews
|
||||
http:
|
||||
- route:
|
||||
- destination:
|
||||
host: reviews
|
||||
subset: v1
|
||||
weight: 50
|
||||
- destination:
|
||||
host: reviews
|
||||
subset: v3
|
||||
weight: 50
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< tab name="Gateway API" category-value="gateway-api" >}}
|
||||
|
||||
{{< text syntax=bash outputis=yaml snip_id=gtw_verify_config_50_v3 >}}
|
||||
$ kubectl get httproute reviews -o yaml
|
||||
apiVersion: gateway.networking.k8s.io/v1beta1
|
||||
kind: HTTPRoute
|
||||
...
|
||||
spec:
|
||||
parentRefs:
|
||||
- group: gateway.networking.k8s.io
|
||||
kind: Service
|
||||
name: reviews
|
||||
port: 9080
|
||||
rules:
|
||||
- backendRefs:
|
||||
- group: ""
|
||||
kind: Service
|
||||
name: reviews-v1
|
||||
port: 9080
|
||||
weight: 50
|
||||
- group: ""
|
||||
kind: Service
|
||||
name: reviews-v3
|
||||
port: 9080
|
||||
weight: 50
|
||||
matches:
|
||||
- path:
|
||||
type: PathPrefix
|
||||
value: /
|
||||
status:
|
||||
parents:
|
||||
- conditions:
|
||||
- lastTransitionTime: "2022-11-10T18:13:43Z"
|
||||
message: Route was valid
|
||||
observedGeneration: 14
|
||||
reason: Accepted
|
||||
status: "True"
|
||||
type: Accepted
|
||||
...
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< /tabset >}}
|
||||
|
||||
5) Refresh the `/productpage` in your browser and you now see *red* colored star ratings approximately 50% of the time. This is because the `v3` version of `reviews` accesses
|
||||
the star ratings service, but the `v1` version does not.
|
||||
|
||||
{{< tip >}}
|
||||
|
@ -88,14 +171,30 @@ the star ratings service, but the `v1` version does not.
|
|||
more often.
|
||||
{{< /tip >}}
|
||||
|
||||
1. Assuming you decide that the `reviews:v3` microservice is stable, you can
|
||||
6) Assuming you decide that the `reviews:v3` microservice is stable, you can
|
||||
route 100% of the traffic to `reviews:v3` by applying this virtual service:
|
||||
|
||||
{{< text syntax=bash snip_id=config_100_v3 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-reviews-v3.yaml@
|
||||
{{< /text >}}
|
||||
{{< tabset category-name="config-api" >}}
|
||||
|
||||
Now when you refresh the `/productpage` you will always see book reviews
|
||||
{{< tab name="Istio classic" category-value="istio-classic" >}}
|
||||
|
||||
{{< text syntax=bash snip_id=config_100_v3 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-reviews-v3.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< tab name="Gateway API" category-value="gateway-api" >}}
|
||||
|
||||
{{< text syntax=bash snip_id=gtw_config_100_v3 >}}
|
||||
$ kubectl apply -f @samples/bookinfo/gateway-api/route-reviews-v3.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< /tabset >}}
|
||||
|
||||
7) Refresh the `/productpage` several times. Now you will always see book reviews
|
||||
with *red* colored star ratings for each review.
|
||||
|
||||
## Understanding what happened
|
||||
|
@ -111,10 +210,26 @@ article [Canary Deployments using Istio](/blog/2017/0.1-canary/).
|
|||
|
||||
1. Remove the application routing rules:
|
||||
|
||||
{{< text syntax=bash snip_id=cleanup >}}
|
||||
$ kubectl delete -f @samples/bookinfo/networking/virtual-service-all-v1.yaml@
|
||||
{{< /text >}}
|
||||
{{< tabset category-name="config-api" >}}
|
||||
|
||||
1. If you are not planning to explore any follow-on tasks, refer to the
|
||||
{{< tab name="Istio classic" category-value="istio-classic" >}}
|
||||
|
||||
{{< text syntax=bash snip_id=cleanup >}}
|
||||
$ kubectl delete -f @samples/bookinfo/networking/virtual-service-all-v1.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< tab name="Gateway API" category-value="gateway-api" >}}
|
||||
|
||||
{{< text syntax=bash snip_id=gtw_cleanup >}}
|
||||
$ kubectl delete httproute reviews
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
||||
{{< /tabset >}}
|
||||
|
||||
2) If you are not planning to explore any follow-on tasks, refer to the
|
||||
[Bookinfo cleanup](/docs/examples/bookinfo/#cleanup) instructions
|
||||
to shutdown the application.
|
||||
|
|
|
@ -19,15 +19,24 @@
|
|||
# WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE:
|
||||
# docs/tasks/traffic-management/traffic-shifting/index.md
|
||||
####################################################################################################
|
||||
source "content/en/boilerplates/snips/gateway-api-gamma-support.sh"
|
||||
|
||||
snip_config_all_v1() {
|
||||
kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
|
||||
}
|
||||
|
||||
snip_gtw_config_all_v1() {
|
||||
kubectl apply -f samples/bookinfo/gateway-api/route-reviews-v1.yaml
|
||||
}
|
||||
|
||||
snip_config_50_v3() {
|
||||
kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-50-v3.yaml
|
||||
}
|
||||
|
||||
snip_gtw_config_50_v3() {
|
||||
kubectl apply -f samples/bookinfo/gateway-api/route-reviews-50-v3.yaml
|
||||
}
|
||||
|
||||
snip_verify_config_50_v3() {
|
||||
kubectl get virtualservice reviews -o yaml
|
||||
}
|
||||
|
@ -51,10 +60,60 @@ spec:
|
|||
weight: 50
|
||||
ENDSNIP
|
||||
|
||||
snip_gtw_verify_config_50_v3() {
|
||||
kubectl get httproute reviews -o yaml
|
||||
}
|
||||
|
||||
! read -r -d '' snip_gtw_verify_config_50_v3_out <<\ENDSNIP
|
||||
apiVersion: gateway.networking.k8s.io/v1beta1
|
||||
kind: HTTPRoute
|
||||
...
|
||||
spec:
|
||||
parentRefs:
|
||||
- group: gateway.networking.k8s.io
|
||||
kind: Service
|
||||
name: reviews
|
||||
port: 9080
|
||||
rules:
|
||||
- backendRefs:
|
||||
- group: ""
|
||||
kind: Service
|
||||
name: reviews-v1
|
||||
port: 9080
|
||||
weight: 50
|
||||
- group: ""
|
||||
kind: Service
|
||||
name: reviews-v3
|
||||
port: 9080
|
||||
weight: 50
|
||||
matches:
|
||||
- path:
|
||||
type: PathPrefix
|
||||
value: /
|
||||
status:
|
||||
parents:
|
||||
- conditions:
|
||||
- lastTransitionTime: "2022-11-10T18:13:43Z"
|
||||
message: Route was valid
|
||||
observedGeneration: 14
|
||||
reason: Accepted
|
||||
status: "True"
|
||||
type: Accepted
|
||||
...
|
||||
ENDSNIP
|
||||
|
||||
snip_config_100_v3() {
|
||||
kubectl apply -f samples/bookinfo/networking/virtual-service-reviews-v3.yaml
|
||||
}
|
||||
|
||||
snip_gtw_config_100_v3() {
|
||||
kubectl apply -f samples/bookinfo/gateway-api/route-reviews-v3.yaml
|
||||
}
|
||||
|
||||
snip_cleanup() {
|
||||
kubectl delete -f samples/bookinfo/networking/virtual-service-all-v1.yaml
|
||||
}
|
||||
|
||||
snip_gtw_cleanup() {
|
||||
kubectl delete httproute reviews
|
||||
}
|
||||
|
|
|
@ -19,20 +19,20 @@ set -e
|
|||
set -u
|
||||
set -o pipefail
|
||||
|
||||
GATEWAY_API="${GATEWAY_API:-false}"
|
||||
|
||||
source "tests/util/samples.sh"
|
||||
|
||||
# @setup profile=default
|
||||
|
||||
kubectl label namespace default istio-injection=enabled --overwrite
|
||||
startup_sleep_sample # needed for sending test requests with curl
|
||||
SLEEP_POD=$(kubectl get pod -l app=sleep -n default -o 'jsonpath={.items..metadata.name}')
|
||||
|
||||
# launch the bookinfo app
|
||||
startup_bookinfo_sample
|
||||
|
||||
# Verification util
|
||||
|
||||
SLEEP_POD=$(kubectl get pod -l app=sleep -n default -o 'jsonpath={.items..metadata.name}')
|
||||
INGRESS_URL="http://istio-ingressgateway.istio-system"
|
||||
# reviews_v3_traffic_percentage
|
||||
# gets the % of productpage requests with reviews from reviews:v3 service
|
||||
# TODO: generalize this function and move to samples.sh so it can be reused by
|
||||
|
@ -43,7 +43,7 @@ function reviews_v3_traffic_percentage() {
|
|||
local v3_count=0
|
||||
local v3_search_string="glyphicon glyphicon-star" # search string present in reviews_v3 response html
|
||||
for ((i = 1; i <= total_request_count; i++)); do
|
||||
if (kubectl exec "${SLEEP_POD}" -c sleep -n "default" -- curl -sS $INGRESS_URL/productpage | grep -q "$v3_search_string"); then
|
||||
if (kubectl exec "${SLEEP_POD}" -c sleep -n "default" -- curl -sS http://productpage:9080/productpage | grep -q "$v3_search_string"); then
|
||||
v3_count=$((v3_count + 1))
|
||||
fi
|
||||
done
|
||||
|
@ -67,16 +67,20 @@ function reviews_v3_traffic_percentage() {
|
|||
|
||||
# Step 1 configure all traffic to v1
|
||||
|
||||
expected="virtualservice.networking.istio.io/productpage created
|
||||
if [ "$GATEWAY_API" == "true" ]; then
|
||||
_verify_same snip_gtw_config_all_v1 "httproute.gateway.networking.k8s.io/reviews created"
|
||||
else
|
||||
expected="virtualservice.networking.istio.io/productpage created
|
||||
virtualservice.networking.istio.io/reviews created
|
||||
virtualservice.networking.istio.io/ratings created
|
||||
virtualservice.networking.istio.io/details created"
|
||||
_verify_same snip_config_all_v1 "$expected"
|
||||
_verify_same snip_config_all_v1 "$expected"
|
||||
|
||||
_wait_for_istio virtualservice default productpage
|
||||
_wait_for_istio virtualservice default reviews
|
||||
_wait_for_istio virtualservice default ratings
|
||||
_wait_for_istio virtualservice default details
|
||||
_wait_for_istio virtualservice default productpage
|
||||
_wait_for_istio virtualservice default reviews
|
||||
_wait_for_istio virtualservice default ratings
|
||||
_wait_for_istio virtualservice default details
|
||||
fi
|
||||
|
||||
# Step 2: verify no rating stars visible, (reviews-v3 traffic=0%)
|
||||
|
||||
|
@ -84,13 +88,24 @@ _verify_same reviews_v3_traffic_percentage 0
|
|||
|
||||
# Step 3: switch 50% traffic to v3
|
||||
|
||||
_verify_same snip_config_50_v3 "virtualservice.networking.istio.io/reviews configured"
|
||||
if [ "$GATEWAY_API" == "true" ]; then
|
||||
_verify_same snip_gtw_config_50_v3 "httproute.gateway.networking.k8s.io/reviews configured"
|
||||
else
|
||||
_verify_same snip_config_50_v3 "virtualservice.networking.istio.io/reviews configured"
|
||||
|
||||
_wait_for_istio virtualservice default reviews
|
||||
_wait_for_istio virtualservice default reviews
|
||||
fi
|
||||
|
||||
# Step 4: Confirm the rule was replaced
|
||||
|
||||
_verify_elided snip_verify_config_50_v3 "$snip_verify_config_50_v3_out"
|
||||
if [ "$GATEWAY_API" == "true" ]; then
|
||||
_verify_lines snip_gtw_verify_config_50_v3 "
|
||||
+ message: Route was valid
|
||||
+ reason: Accepted
|
||||
"
|
||||
else
|
||||
_verify_elided snip_verify_config_50_v3 "$snip_verify_config_50_v3_out"
|
||||
fi
|
||||
|
||||
# Step 5: verify rating stars visible 50% of the time
|
||||
|
||||
|
@ -98,13 +113,19 @@ _verify_same reviews_v3_traffic_percentage 50
|
|||
|
||||
# Step 6: route 100% traffic to v3
|
||||
|
||||
snip_config_100_v3
|
||||
if [ "$GATEWAY_API" == "true" ]; then
|
||||
snip_gtw_config_100_v3
|
||||
else
|
||||
snip_config_100_v3
|
||||
|
||||
_wait_for_istio virtualservice default reviews
|
||||
_wait_for_istio virtualservice default reviews
|
||||
fi
|
||||
|
||||
_verify_same reviews_v3_traffic_percentage 100
|
||||
|
||||
# @cleanup
|
||||
snip_cleanup
|
||||
cleanup_bookinfo_sample
|
||||
cleanup_sleep_sample
|
||||
if [ "$GATEWAY_API" != "true" ]; then
|
||||
snip_cleanup
|
||||
cleanup_bookinfo_sample
|
||||
cleanup_sleep_sample
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue