From ef797a12892e135f2cea712f6c8faece97319274 Mon Sep 17 00:00:00 2001 From: Rajakavitha Date: Wed, 18 Oct 2023 13:52:20 +0530 Subject: [PATCH 1/3] rewrite of the guide --- Gemfile.lock | 2 +- .../kic-v2/guides/using-multiple-backends.md | 173 ++++++++---------- 2 files changed, 82 insertions(+), 93 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1419a9faeab0..326d16a976f6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -188,4 +188,4 @@ DEPENDENCIES rubocop BUNDLED WITH - 2.4.10 + 2.4.21 diff --git a/app/_src/kic-v2/guides/using-multiple-backends.md b/app/_src/kic-v2/guides/using-multiple-backends.md index 77024670dd3c..b20ced44ad21 100644 --- a/app/_src/kic-v2/guides/using-multiple-backends.md +++ b/app/_src/kic-v2/guides/using-multiple-backends.md @@ -8,109 +8,98 @@ stability_message: | ## Overview -HTTPRoute supports adding multiple Services under its -`BackendRefs` field. When you add multiple Services, -requests through the HTTPRoute are distributed across the Services. This guide -walks through creating an HTTPRoute with multiple backend Services. +HTTPRoute supports adding multiple Services under its `BackendRefs` field. When you add multiple Services, +requests through the HTTPRoute are distributed across the Services. This guide walks through creating an HTTPRoute with multiple backend Services. -{% include /md/kic/installation.md %} +{% include_cached /md/kic/prerequisites.md kong_version=page.kong_version disable_gateway_api=false %} {% include /md/kic/class.md %} -## Deploy multiple Services +## Deploy multiple Services with HTTPRoute -To do so, you can deploy a second echo Service so that you have -a second `BackendRef` to use for traffic splitting: -```bash -kubectl apply -f {{site.links.web}}/assets/kubernetes-ingress-controller/examples/echo-services.yaml -``` -Response: -```text -service/echo created -deployment.apps/echo created -service/echo2 created -deployment.apps/echo2 created -``` +1. Deploy a second echo Service so that you have a second `BackendRef` to use for traffic splitting: + ```bash + kubectl apply -f {{site.links.web}}/assets/kubernetes-ingress-controller/examples/echo-services.yaml + ``` + The results should look like this: + ```text + service/echo created + deployment.apps/echo created + service/echo2 created + deployment.apps/echo2 created + ``` -## Create a multi-Service HTTPRoute +1. Deploy an HTTPRoute that sends traffic to both the services. By default, traffic is distributed evenly across all services: -Now that those two Services are deployed, you can now deploy an HTTPRoute that -sends traffic to both of them. By default, traffic is distributed evenly across -all Services: + ```bash + echo 'apiVersion: gateway.networking.k8s.io/v1beta1 + kind: HTTPRoute + metadata: + name: echo + annotations: + konghq.com/strip-path: "true" + spec: + parentRefs: + - name: kong + rules: + - matches: + - path: + type: PathPrefix + value: /echo + backendRefs: + - name: echo + kind: Service + port: 80 + - name: echo2 + kind: Service + port: 80 + ' | kubectl apply -f - + ``` + The results should look like this: + ```text + httproute.gateway.networking.k8s.io/echo created + ``` -```bash -echo 'apiVersion: gateway.networking.k8s.io/v1beta1 -kind: HTTPRoute -metadata: - name: echo - annotations: - konghq.com/strip-path: "true" -spec: - parentRefs: - - name: kong - rules: - - matches: - - path: - type: PathPrefix - value: /echo - backendRefs: - - name: echo - kind: Service - port: 80 - - name: echo2 - kind: Service - port: 80 -' | kubectl apply -f - -``` -Response: -```text -httproute.gateway.networking.k8s.io/echo created -``` - -Sending many requests through this route and tabulating the results will show -an even distribution of requests across the Services: -```bash -curl -s 192.168.96.0/echo/hostname?iteration=[1-200] -w "\n" | sort | uniq -c -``` -Response: -```text -100 echo2-7cb798f47-gv6hs -100 echo-658c5ff5ff-tv275 -``` +1. Send multiple requests through this route and tabulating the results to check an even distribution of requests across the Services: + ```bash + curl -s "$PROXY_IP/echo/hostname?iteration="{1..200} -w "\n" | sort | uniq -c + ``` + The results should look like this: + ```text + 100 echo2-7cb798f47-gv6hs + 100 echo-658c5ff5ff-tv275 + ``` ## Add Service weights -The `weight` field overrides the default distribution of requests across -Services. Each Service instead receives `weight / sum(all Service weights)` -percent of the requests. Add weights to the Services in the HTTPRoute's -backend list: +The `weight` field overrides the default distribution of requests across Services. Each Service instead receives `weight / sum(all Service weights)` percent of the requests. +1. Add weights to the Services in the HTTPRoute's backend list. -```bash -kubectl patch --type json httproute echo -p='[ - { - "op":"add", - "path":"/spec/rules/0/backendRefs/0/weight", - "value":200 - }, - { "op":"add", - "path":"/spec/rules/0/backendRefs/1/weight", - "value":100 - } -]' -``` -Response: -```text -httproute.gateway.networking.k8s.io/echo patched -``` + ```bash + kubectl patch --type json httproute echo -p='[ + { + "op":"add", + "path":"/spec/rules/0/backendRefs/0/weight", + "value":200 + }, + { "op":"add", + "path":"/spec/rules/0/backendRefs/1/weight", + "value":100 + } + ]' + ``` + The results should look like this: + ```text + httproute.gateway.networking.k8s.io/echo patched + ``` -Sending the same requests will now show roughly 1/3 of the requests going to -`echo2` and 2/3 going to `echo`: +1. Send the same requests and roughly 1/3 of the requests go to `echo2` and 2/3 going to `echo`: -```bash -curl -s 192.168.96.0/echo/hostname?iteration=[1-200] -w "\n" | sort | uniq -c -``` -Response: -```text - 67 echo2-7cb798f47-gv6hs -133 echo-658c5ff5ff-tv275 -``` + ```bash + curl -s "$PROXY_IP/echo/hostname?iteration="{1..200} -w "\n" | sort | uniq -c + ``` + The results should look like this: + ```text + 67 echo2-7cb798f47-gv6hs + 133 echo-658c5ff5ff-tv275 + ``` From 39ab5b0bd4e39c7726d46674ec697517697cbf12 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Wed, 18 Oct 2023 09:32:24 +0100 Subject: [PATCH 2/3] Cleanup alignment of examples. Remove GatewayClass include --- app/_src/kic-v2/guides/using-multiple-backends.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/_src/kic-v2/guides/using-multiple-backends.md b/app/_src/kic-v2/guides/using-multiple-backends.md index b20ced44ad21..77b33d6bfec5 100644 --- a/app/_src/kic-v2/guides/using-multiple-backends.md +++ b/app/_src/kic-v2/guides/using-multiple-backends.md @@ -13,8 +13,6 @@ requests through the HTTPRoute are distributed across the Services. This guide w {% include_cached /md/kic/prerequisites.md kong_version=page.kong_version disable_gateway_api=false %} -{% include /md/kic/class.md %} - ## Deploy multiple Services with HTTPRoute 1. Deploy a second echo Service so that you have a second `BackendRef` to use for traffic splitting: @@ -78,13 +76,14 @@ The `weight` field overrides the default distribution of requests across Service ```bash kubectl patch --type json httproute echo -p='[ { - "op":"add", - "path":"/spec/rules/0/backendRefs/0/weight", - "value":200 + "op":"add", + "path":"/spec/rules/0/backendRefs/0/weight", + "value":200 }, - { "op":"add", - "path":"/spec/rules/0/backendRefs/1/weight", - "value":100 + { + "op":"add", + "path":"/spec/rules/0/backendRefs/1/weight", + "value":100 } ]' ``` From c1ae1396722a10b51f360aad45a0b86caf5ffa80 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Wed, 18 Oct 2023 09:34:18 +0100 Subject: [PATCH 3/3] Merge KIC 3.0 prerequisites in to KIC 2.x --- app/_includes/md/kic/prerequisites.md | 81 ++++++++++++++++++++++----- 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/app/_includes/md/kic/prerequisites.md b/app/_includes/md/kic/prerequisites.md index 4f03c359c50a..40aa0bd06e87 100644 --- a/app/_includes/md/kic/prerequisites.md +++ b/app/_includes/md/kic/prerequisites.md @@ -1,18 +1,64 @@
-

Before you begin ensure that you have Installed {{site.kic_product_name}} in your Kubernetes cluster and are able to connect to Kong.

+

Before you begin ensure that you have Installed {{site.kic_product_name}} {% unless include.disable_gateway_api %}with Gateway API support {% endunless %}in your Kubernetes cluster and are able to connect to Kong.

+## Prerequisites + {% unless include.disable_gateway_api %} -## Install the Gateway APIs +### Install the Gateway APIs + +1. Install the Gateway API CRDs before installing {{ site.kic_product_name }}. + + ```bash + kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.8.1/standard-install.yaml + ``` + + {% if include.gateway_api_experimental %} + +1. Install the experimental Gateway API CRDs to test this feature. + + ```bash + kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v0.8.1/experimental-install.yaml + ``` + {% endif %} -If you wish to use the Gateway APIs examples, ensure that you enable support for [ -Gateway APIs in KIC](/kubernetes-ingress-controller/{{page.kong_version}}/deployment/install-gateway-apis). +1. Create a `Gateway` and `GatewayClass` instance to use. + + ```bash + echo " + --- + apiVersion: gateway.networking.k8s.io/v1beta1 + kind: GatewayClass + metadata: + name: kong + annotations: + konghq.com/gatewayclass-unmanaged: 'true' + + spec: + controllerName: konghq.com/kic-gateway-controller + --- + apiVersion: gateway.networking.k8s.io/v1beta1 + kind: Gateway + metadata: + name: kong + spec: + gatewayClassName: kong + listeners: + - name: proxy + port: 80 + protocol: HTTP + " | kubectl apply -f - + ``` {% endunless %} + The results should look like this: + ```text + gatewayclass.gateway.networking.k8s.io/kong created + gateway.gateway.networking.k8s.io/kong created + ``` -## Prerequisites ### Install Kong You can install Kong in your Kubernetes cluster using [Helm](https://helm.sh/). @@ -29,6 +75,20 @@ You can install Kong in your Kubernetes cluster using [Helm](https://helm.sh/). helm install kong kong/ingress -n kong --create-namespace ``` +{% if include.gateway_api_experimental %} +1. Enable the Gateway API Alpha feature gate: + + ```bash + kubectl set env -n kong deployment/kong-controller CONTROLLER_FEATURE_GATES="GatewayAlpha=true" -c ingress-controller + ``` + + The results should look like this: + ```text + deployment.apps/kong-controller env updated + ``` +{% endif %} + + ### Test connectivity to Kong Kubernetes exposes the proxy through a Kubernetes service. Run the following commands to store the load balancer IP address in a variable named `PROXY_IP`: @@ -36,10 +96,8 @@ Kubernetes exposes the proxy through a Kubernetes service. Run the following com 1. Populate `$PROXY_IP` for future commands: ```bash - HOST=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{.status.loadBalancer.ingress[0].ip}') - PORT=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{.spec.ports[0].port}') - export PROXY_IP=${HOST}:${PORT} - echo $PROXY_IP + export PROXY_IP=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo $PROXY_IP ``` 2. Ensure that you can call the proxy IP: @@ -60,7 +118,4 @@ Kubernetes exposes the proxy through a Kubernetes service. Run the following com {"message":"no Route matched with those values"} ``` - - If you are not able to connect to Kong, read the [deployment guide](/kubernetes-ingress-controller/{{ page.release }}/deployment/overview/). - -
+ \ No newline at end of file