From d37f7cdf58ee748c1d806ec4f9b10b79ccc569e3 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Fri, 4 Apr 2025 09:52:39 -0600 Subject: [PATCH] Update NGF demo README Update the NGF demo README to include full steps to the demo. --- nginx-gateway-fabric/appworld/README.md | 107 +++++++++++++++++- .../appworld/cafe-route-equal-weight.yaml | 4 +- 2 files changed, 104 insertions(+), 7 deletions(-) diff --git a/nginx-gateway-fabric/appworld/README.md b/nginx-gateway-fabric/appworld/README.md index d515f76..8f00307 100644 --- a/nginx-gateway-fabric/appworld/README.md +++ b/nginx-gateway-fabric/appworld/README.md @@ -1,15 +1,112 @@ # NGINX Gateway Fabric Demo -This demo contains the files used in the NGINX Gateway Fabric AppWorld demo. +In this demo we will deploy NGINX Gateway Fabric and configure traffic splitting for a simple cafe application. +We will use HTTPRoute resources to split traffic between two versions of the application -- `coffee-v1` +and `coffee-v2`. -To install the Gateway API CRDs: + +## Running the Example + +## 1. Deploy NGINX Gateway Fabric + +1. Follow the [installation instructions](https://docs.nginx.com/nginx-gateway-fabric/installation/) to deploy NGINX Gateway Fabric. + +1. Save the public IP address of NGINX Gateway Fabric into a shell variable: + + ```text + GW_IP=XXX.YYY.ZZZ.III + ``` + +1. Save the port of NGINX Gateway Fabric: + + ```text + GW_PORT= + ``` + +This assumes that you have an accessible external IP address. If not, you can port-forward the nginx service to localhost and access it using `127.0.0.1:8080` instead. ```shell -kubectl kustomize "https://github.com/nginx/nginx-gateway-fabric/config/crd/gateway-api/standard?ref=v1.6.1" | kubectl apply -f - +kubectl -n nginx-gateway port-forward svc/ 8080:80 & ``` -To install NGINX Gateway Fabric: +## 2. Deploy the Coffee Application + +1. Create the Cafe Deployments and Services: + + ```shell + kubectl apply -f coffee-app.yaml + ``` + +1. Check that the Pods are running in the `default` Namespace: + + ```shell + kubectl get pods + ``` + + ```text + NAME READY STATUS RESTARTS AGE + coffee-v1-7c57c576b-rfjsh 1/1 Running 0 21m + coffee-v2-698f66dc46-vcb6r 1/1 Running 0 21m + ``` + +## 3. Configure Routing + +1. Create the Gateway: + + ```shell + kubectl apply -f gateway.yaml + ``` + +1. Create the HTTPRoute resource: + + ```shell + kubectl apply -f cafe-route.yaml + ``` + +This HTTPRoute resource defines a route for the path `/coffee` that sends 80% of the requests to `coffee-v1` and 20% +to `coffee-v2`. In this example, we use 80 and 20; however, the weights are calculated proportionally and do not need to +sum to 100. For example, the weights of 8 and 2, 16 and 4, or 32 and 8 all evaluate to the same relative proportions. + +## 4. Test the Application + +To access the application, we will use `curl` to send requests to `/coffee`: ```shell -helm install ngf oci://ghcr.io/nginx/charts/nginx-gateway-fabric --create-namespace -n nginx-gateway +curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee +``` + +80% of the responses will come from `coffee-v1`: + +```text +Server address: 10.12.0.18:80 +Server name: coffee-v1-7c57c576b-rfjsh +``` + +20% of the responses will come from `coffee-v2`: + +```text +Server address: 10.12.0.19:80 +Server name: coffee-v2-698f66dc46-vcb6r ``` + +### 5. Modify the Traffic Split Configuration + +Let's shift more of the traffic to `coffee-v2`. To do this we will update the HTTPRoute resource and change the weight +of the `coffee-v2` backend to 80. Backends with equal weights will receive an equal share of traffic. + +1. Apply the updated HTTPRoute resource: + + ```shell + kubectl apply -f cafe-route-equal-weight.yaml + ``` + +2. Test the application again: + + ```shell + curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee + ``` + +The responses will now be split evenly between `coffee-v1` and `coffee-v2`. + +We can continue modifying the weights of the backends to shift more and more traffic to `coffee-v2`.`cafe-route-v2.yaml` will shift 100% of traffic to `coffee-v2`. +If there's an issue with `coffee-v2`, we can quickly shift traffic back to `coffee-v1`. diff --git a/nginx-gateway-fabric/appworld/cafe-route-equal-weight.yaml b/nginx-gateway-fabric/appworld/cafe-route-equal-weight.yaml index 58e6d69..aa0e1f4 100644 --- a/nginx-gateway-fabric/appworld/cafe-route-equal-weight.yaml +++ b/nginx-gateway-fabric/appworld/cafe-route-equal-weight.yaml @@ -16,7 +16,7 @@ spec: backendRefs: - name: coffee-v1 port: 80 - weight: 50 + weight: 80 - name: coffee-v2 port: 80 - weight: 50 + weight: 80