diff --git a/docs/application-layer/global-rate-limiting.md b/docs/application-layer/global-rate-limiting.md new file mode 100644 index 00000000..96f69c69 --- /dev/null +++ b/docs/application-layer/global-rate-limiting.md @@ -0,0 +1,369 @@ +--- +title: Global Rate Limiting +sidebar_position: 12 +--- + +This document provides a step-by-step guide on how to test the global rate limiting functionality of kmesh. It covers deploying the necessary components, configuring traffic rules with an external rate limiting service, and observing the rate limiting behavior across multiple proxy instances. + +## Step 1. Deploy Kmesh and istiod (>=1.24) + +Please read [Quick Start](https://kmesh.net/docs/setup/quick-start) to complete the deployment of kmesh. + +## Step 2. Deploy sleep and httpbin + +We will deploy `httpbin` as the backend service for receiving requests and `sleep` as the client for sending requests. + +``` sh +kubectl apply -f samples/sleep/sleep.yaml +kubectl apply -f samples/httpbin/httpbin.yaml +``` + +## Step 3. Deploy Redis for global rate limiting + +Global rate limiting requires an external service to coordinate rate limits across multiple proxy instances. We'll use Redis for this purpose. + +```sh +kubectl apply -f -< /dev/null || \ + { kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd/experimental?ref=444631bfe06f3bcca5d0eadf1857eac1d369421d" | kubectl apply -f -; } +``` + +Next, create a dedicated Waypoint proxy for the `httpbin` service and label the service to direct its traffic through this Waypoint. + +```sh +kmeshctl waypoint apply -n default --name httpbin-waypoint --image ghcr.io/kmesh-net/waypoint:latest + +kubectl label service httpbin istio.io/use-waypoint=httpbin-waypoint +``` + +## Step 6. Deploy envoyFilter + +This `EnvoyFilter` resource injects a global rate-limiting filter into the `httpbin` service's Waypoint proxy. The filter is configured with the following rules: + +- A request with the header `quota: low` will be limited to **1 request per second** globally. +- A request with the header `quota: medium` will be limited to **3 requests per second** globally. +- Other requests will be subject to a default limit of **10 requests per second** globally. + +The `workloadSelector` ensures that this filter is applied only to the `httpbin-waypoint` proxy. + +```sh +kubectl apply -f -<