|
1 | 1 | # NGINX Gateway Fabric Demo
|
2 | 2 |
|
3 |
| -This demo contains the files used in the NGINX Gateway Fabric AppWorld demo. |
| 3 | +In this demo we will deploy NGINX Gateway Fabric and configure traffic splitting for a simple cafe application. |
| 4 | +We will use HTTPRoute resources to split traffic between two versions of the application -- `coffee-v1` |
| 5 | +and `coffee-v2`. |
4 | 6 |
|
5 |
| -To install the Gateway API CRDs: |
| 7 | + |
| 8 | +## Running the Example |
| 9 | + |
| 10 | +## 1. Deploy NGINX Gateway Fabric |
| 11 | + |
| 12 | +1. Follow the [installation instructions](https://docs.nginx.com/nginx-gateway-fabric/installation/) to deploy NGINX Gateway Fabric. |
| 13 | + |
| 14 | +1. Save the public IP address of NGINX Gateway Fabric into a shell variable: |
| 15 | + |
| 16 | + ```text |
| 17 | + GW_IP=XXX.YYY.ZZZ.III |
| 18 | + ``` |
| 19 | + |
| 20 | +1. Save the port of NGINX Gateway Fabric: |
| 21 | + |
| 22 | + ```text |
| 23 | + GW_PORT=<port number> |
| 24 | + ``` |
| 25 | + |
| 26 | +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. |
6 | 27 |
|
7 | 28 | ```shell
|
8 |
| -kubectl kustomize "https://github.com/nginx/nginx-gateway-fabric/config/crd/gateway-api/standard?ref=v1.6.1" | kubectl apply -f - |
| 29 | +kubectl -n nginx-gateway port-forward svc/<ngf-service-name> 8080:80 & |
9 | 30 | ```
|
10 | 31 |
|
11 |
| -To install NGINX Gateway Fabric: |
| 32 | +## 2. Deploy the Coffee Application |
| 33 | + |
| 34 | +1. Create the Cafe Deployments and Services: |
| 35 | + |
| 36 | + ```shell |
| 37 | + kubectl apply -f coffee-app.yaml |
| 38 | + ``` |
| 39 | + |
| 40 | +1. Check that the Pods are running in the `default` Namespace: |
| 41 | + |
| 42 | + ```shell |
| 43 | + kubectl get pods |
| 44 | + ``` |
| 45 | + |
| 46 | + ```text |
| 47 | + NAME READY STATUS RESTARTS AGE |
| 48 | + coffee-v1-7c57c576b-rfjsh 1/1 Running 0 21m |
| 49 | + coffee-v2-698f66dc46-vcb6r 1/1 Running 0 21m |
| 50 | + ``` |
| 51 | + |
| 52 | +## 3. Configure Routing |
| 53 | + |
| 54 | +1. Create the Gateway: |
| 55 | + |
| 56 | + ```shell |
| 57 | + kubectl apply -f gateway.yaml |
| 58 | + ``` |
| 59 | + |
| 60 | +1. Create the HTTPRoute resource: |
| 61 | + |
| 62 | + ```shell |
| 63 | + kubectl apply -f cafe-route.yaml |
| 64 | + ``` |
| 65 | + |
| 66 | +This HTTPRoute resource defines a route for the path `/coffee` that sends 80% of the requests to `coffee-v1` and 20% |
| 67 | +to `coffee-v2`. In this example, we use 80 and 20; however, the weights are calculated proportionally and do not need to |
| 68 | +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. |
| 69 | + |
| 70 | +## 4. Test the Application |
| 71 | + |
| 72 | +To access the application, we will use `curl` to send requests to `/coffee`: |
12 | 73 |
|
13 | 74 | ```shell
|
14 |
| -helm install ngf oci://ghcr.io/nginx/charts/nginx-gateway-fabric --create-namespace -n nginx-gateway |
| 75 | +curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee |
| 76 | +``` |
| 77 | + |
| 78 | +80% of the responses will come from `coffee-v1`: |
| 79 | + |
| 80 | +```text |
| 81 | +Server address: 10.12.0.18:80 |
| 82 | +Server name: coffee-v1-7c57c576b-rfjsh |
| 83 | +``` |
| 84 | + |
| 85 | +20% of the responses will come from `coffee-v2`: |
| 86 | + |
| 87 | +```text |
| 88 | +Server address: 10.12.0.19:80 |
| 89 | +Server name: coffee-v2-698f66dc46-vcb6r |
15 | 90 | ```
|
| 91 | + |
| 92 | +### 5. Modify the Traffic Split Configuration |
| 93 | + |
| 94 | +Let's shift more of the traffic to `coffee-v2`. To do this we will update the HTTPRoute resource and change the weight |
| 95 | +of the `coffee-v2` backend to 80. Backends with equal weights will receive an equal share of traffic. |
| 96 | + |
| 97 | +1. Apply the updated HTTPRoute resource: |
| 98 | + |
| 99 | + ```shell |
| 100 | + kubectl apply -f cafe-route-equal-weight.yaml |
| 101 | + ``` |
| 102 | + |
| 103 | +2. Test the application again: |
| 104 | + |
| 105 | + ```shell |
| 106 | + curl --resolve cafe.example.com:$GW_PORT:$GW_IP http://cafe.example.com:$GW_PORT/coffee |
| 107 | + ``` |
| 108 | + |
| 109 | +The responses will now be split evenly between `coffee-v1` and `coffee-v2`. |
| 110 | + |
| 111 | +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`. |
| 112 | +If there's an issue with `coffee-v2`, we can quickly shift traffic back to `coffee-v1`. |
0 commit comments