From e6ab3f286fbfdee44123fd1abbd3573ce5dbab76 Mon Sep 17 00:00:00 2001 From: Peter Jausovec Date: Mon, 29 Jul 2024 02:41:35 -0700 Subject: [PATCH] fix formatting in mirroring task (#15446) * fix formatting in mirroring task Signed-off-by: Peter Jausovec * fix linting issues Signed-off-by: Peter Jausovec * updated snips Signed-off-by: Peter Jausovec * add namespace label back Signed-off-by: Peter Jausovec * ugh Signed-off-by: Peter Jausovec * getting there ... Signed-off-by: Peter Jausovec * remove the ns label at the end of the test Signed-off-by: Peter Jausovec * Update content/en/docs/tasks/traffic-management/mirroring/index.md Co-authored-by: Michael * indent the tab sections Signed-off-by: Peter Jausovec * pr feedback Signed-off-by: Peter Jausovec * typo fix --------- Signed-off-by: Peter Jausovec Co-authored-by: Michael --- .../traffic-management/mirroring/index.md | 534 +++++++++--------- .../traffic-management/mirroring/snips.sh | 35 +- .../traffic-management/mirroring/test.sh | 13 +- 3 files changed, 287 insertions(+), 295 deletions(-) diff --git a/content/en/docs/tasks/traffic-management/mirroring/index.md b/content/en/docs/tasks/traffic-management/mirroring/index.md index 84b8f8bc35..9054d178a0 100644 --- a/content/en/docs/tasks/traffic-management/mirroring/index.md +++ b/content/en/docs/tasks/traffic-management/mirroring/index.md @@ -21,97 +21,93 @@ you will apply a rule to mirror a portion of traffic to `v2`. ## Before you begin -* Set up Istio by following the instructions in the - [Installation guide](/docs/setup/). +1. Set up Istio by following the [Installation guide](/docs/setup/). +1. Start by deploying two versions of the [httpbin]({{< github_tree >}}/samples/httpbin) service that have access logging enabled: -* Start by deploying two versions of the [httpbin]({{< github_tree >}}/samples/httpbin) service that have access logging enabled: + 1. Deploy `httpbin-v1`: - **httpbin-v1:** - - {{< text bash >}} - $ cat <}} + $ kubectl create -f - <}} + + 1. Deploy `httpbin-v2`: + + {{< text bash >}} + $ kubectl create -f - <}} + + 1. Deploy the `httpbin` Kubernetes service: + + {{< text bash >}} + $ kubectl create -f - <}} - - **httpbin-v2:** - - {{< text bash >}} - $ cat <}} + EOF + {{< /text >}} - **httpbin Kubernetes service:** +1. Deploy the `sleep` workload you'll use to send requests to the `httpbin` service: {{< text bash >}} - $ kubectl create -f - <}} - -* Start the `sleep` service so you can use `curl` to provide load: - - **sleep service:** - - {{< text bash >}} - $ cat <}} + {{< tabset category-name="config-api" >}} -{{< tab name="Istio APIs" category-value="istio-apis" >}} + {{< tab name="Istio APIs" category-value="istio-apis" >}} -{{< text bash >}} -$ kubectl apply -f - <}} + {{< text bash >}} + $ kubectl apply -f - <}} -{{< /tab >}} + {{< /tab >}} -{{< tab name="Gateway API" category-value="gateway-api" >}} + {{< tab name="Gateway API" category-value="gateway-api" >}} -{{< text bash >}} -$ kubectl apply -f - <}} + $ kubectl apply -f - <}} + metadata: + name: httpbin-v1 + spec: + ports: + - port: 80 + name: http + selector: + app: httpbin + version: v1 + --- + apiVersion: v1 + kind: Service + metadata: + name: httpbin-v2 + spec: + ports: + - port: 80 + name: http + selector: + app: httpbin + version: v2 + --- + apiVersion: gateway.networking.k8s.io/v1 + kind: HTTPRoute + metadata: + name: httpbin + spec: + parentRefs: + - group: "" + kind: Service + name: httpbin + port: 8000 + rules: + - backendRefs: + - name: httpbin-v1 + port: 80 + EOF + {{< /text >}} -{{< /tab >}} + {{< /tab >}} -{{< /tabset >}} + {{< /tabset >}} -2) Now, with all traffic directed to `httpbin:v1`, send a request to the service: +1. Now, with all traffic directed to `httpbin:v1`, send a request to the service: {{< text bash json >}} - $ export SLEEP_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name}) - $ kubectl exec "${SLEEP_POD}" -c sleep -- curl -sS http://httpbin:8000/headers + $ kubectl exec deploy/sleep -c sleep -- curl -sS http://httpbin:8000/headers { "headers": { "Accept": "*/*", @@ -249,153 +244,150 @@ EOF } {{< /text >}} -3) Check the logs for `v1` and `v2` of the `httpbin` pods. You should see access -log entries for `v1` and none for `v2`: +1. Check the logs from `httpbin-v1` and `httpbin-v2` pods. You should see access log entries for `v1` and none for `v2`: {{< text bash >}} - $ export V1_POD=$(kubectl get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name}) - $ kubectl logs "$V1_POD" -c httpbin + $ kubectl logs deploy/httpbin-v1 -c httpbin 127.0.0.1 - - [07/Mar/2018:19:02:43 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" {{< /text >}} {{< text bash >}} - $ export V2_POD=$(kubectl get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name}) - $ kubectl logs "$V2_POD" -c httpbin + $ kubectl logs deploy/httpbin-v2 -c httpbin {{< /text >}} -## Mirroring traffic to v2 +## Mirroring traffic to `httpbin-v2` -1. Change the route rule to mirror traffic to v2: +1. Change the route rule to mirror traffic to `httpbin-v2`: -{{< tabset category-name="config-api" >}} + {{< tabset category-name="config-api" >}} -{{< tab name="Istio APIs" category-value="istio-apis" >}} - -{{< text bash >}} -$ kubectl apply -f - <}} - -This route rule sends 100% of the traffic to `v1`. The last stanza specifies -that you want to mirror (i.e., also send) 100% of the same traffic to the -`httpbin:v2` service. When traffic gets mirrored, -the requests are sent to the mirrored service with their Host/Authority headers -appended with `-shadow`. For example, `cluster-1` becomes `cluster-1-shadow`. - -Also, it is important to note that these requests are mirrored as "fire and -forget", which means that the responses are discarded. - -You can use the `value` field under the `mirrorPercentage` field to mirror a fraction of the traffic, -instead of mirroring all requests. If this field is absent, all traffic will be mirrored. - -{{< /tab >}} - -{{< tab name="Gateway API" category-value="gateway-api" >}} - -{{< text bash >}} -$ kubectl apply -f - <}} - -This route rule sends 100% of the traffic to `v1`. The `RequestMirror` filter -specifies that you want to mirror (i.e., also send) 100% of the same traffic to the -`httpbin:v2` service. When traffic gets mirrored, -the requests are sent to the mirrored service with their Host/Authority headers -appended with `-shadow`. For example, `cluster-1` becomes `cluster-1-shadow`. - -Also, it is important to note that these requests are mirrored as "fire and -forget", which means that the responses are discarded. - -{{< /tab >}} - -{{< /tabset >}} - -2) Send in traffic: + {{< tab name="Istio APIs" category-value="istio-apis" >}} {{< text bash >}} - $ kubectl exec "${SLEEP_POD}" -c sleep -- curl -sS http://httpbin:8000/headers + $ kubectl apply -f - <}} + + This route rule sends 100% of the traffic to `v1`. The last stanza specifies + that you want to mirror (i.e., also send) 100% of the same traffic to the + `httpbin:v2` service. When traffic gets mirrored, + the requests are sent to the mirrored service with their Host/Authority headers + appended with `-shadow`. For example, `cluster-1` becomes `cluster-1-shadow`. + + Also, it is important to note that these requests are mirrored as "fire and + forget", which means that the responses are discarded. + + You can use the `value` field under the `mirrorPercentage` field to mirror a fraction of the traffic, + instead of mirroring all requests. If this field is absent, all traffic will be mirrored. + + {{< /tab >}} + + {{< tab name="Gateway API" category-value="gateway-api" >}} + + {{< text bash >}} + $ kubectl apply -f - <}} + + This route rule sends 100% of the traffic to `v1`. The `RequestMirror` filter + specifies that you want to mirror (i.e., also send) 100% of the same traffic to the + `httpbin:v2` service. When traffic gets mirrored, + the requests are sent to the mirrored service with their Host/Authority headers + appended with `-shadow`. For example, `cluster-1` becomes `cluster-1-shadow`. + + Also, it is important to note that these requests are mirrored as "fire and + forget", which means that the responses are discarded. + + {{< /tab >}} + + {{< /tabset >}} + +1. Send the traffic: + + {{< text bash >}} + $ kubectl exec deploy/sleep -c sleep -- curl -sS http://httpbin:8000/headers {{< /text >}} Now, you should see access logging for both `v1` and `v2`. The access logs created in `v2` are the mirrored requests that are actually going to `v1`. {{< text bash >}} - $ kubectl logs "$V1_POD" -c httpbin + $ kubectl logs deploy/httpbin-v1 -c httpbin 127.0.0.1 - - [07/Mar/2018:19:02:43 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" 127.0.0.1 - - [07/Mar/2018:19:26:44 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" {{< /text >}} {{< text bash >}} - $ kubectl logs "$V2_POD" -c httpbin + $ kubectl logs deploy/httpbin-v2 -c httpbin 127.0.0.1 - - [07/Mar/2018:19:26:44 +0000] "GET /headers HTTP/1.1" 200 361 "-" "curl/7.35.0" {{< /text >}} ## Cleaning up -1. Remove the rules: +1. Remove the rules: -{{< tabset category-name="config-api" >}} + {{< tabset category-name="config-api" >}} -{{< tab name="Istio APIs" category-value="istio-apis" >}} + {{< tab name="Istio APIs" category-value="istio-apis" >}} -{{< text bash >}} -$ kubectl delete virtualservice httpbin -$ kubectl delete destinationrule httpbin -{{< /text >}} + {{< text bash >}} + $ kubectl delete virtualservice httpbin + $ kubectl delete destinationrule httpbin + {{< /text >}} -{{< /tab >}} + {{< /tab >}} -{{< tab name="Gateway API" category-value="gateway-api" >}} + {{< tab name="Gateway API" category-value="gateway-api" >}} -{{< text bash >}} -$ kubectl delete httproute httpbin -$ kubectl delete svc httpbin-v1 httpbin-v2 -{{< /text >}} + {{< text bash >}} + $ kubectl delete httproute httpbin + $ kubectl delete svc httpbin-v1 httpbin-v2 + {{< /text >}} -{{< /tab >}} + {{< /tab >}} -{{< /tabset >}} + {{< /tabset >}} -2) Shutdown the [httpbin]({{< github_tree >}}/samples/httpbin) service and client: +1. Delete `httpbin` and `sleep` deployments and `httpbin` service: {{< text bash >}} $ kubectl delete deploy httpbin-v1 httpbin-v2 sleep diff --git a/content/en/docs/tasks/traffic-management/mirroring/snips.sh b/content/en/docs/tasks/traffic-management/mirroring/snips.sh index f4a7f2b35e..3178aab004 100644 --- a/content/en/docs/tasks/traffic-management/mirroring/snips.sh +++ b/content/en/docs/tasks/traffic-management/mirroring/snips.sh @@ -22,7 +22,7 @@ source "content/en/boilerplates/snips/gateway-api-support.sh" snip_before_you_begin_1() { -cat < ENDSNIP -snip_mirroring_traffic_to_v2_1() { +snip_mirroring_traffic_to_httpbinv2_1() { kubectl apply -f - <