You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/ngf/traffic-management/session-persistence.md
+17-8Lines changed: 17 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,11 @@ Learn how to configure session persistence using NGINX Gateway Fabric.
11
11
12
12
## Overview
13
13
14
-
In this guide, you’ll learn how to configure session persistence for your application. Session persistence ensures that multiple requests from the same client are consistently routed to the same backend Pod. This is useful when your application maintains in-memory state (for example, shopping carts or user sessions). NGINX Gateway Fabric supports configuring session persistence via `UpstreamSettingsPolicy` resource or directly on `HTTPRoute` and `GRPCRoute` resources. For NGINX OSS users, using the `ip_hash` load-balancing method provides basic session affinity by routing requests from the same client IP to the same backend Pod. For NGINX Plus users, the `sticky cookie` directive can be used to provide true session persistence based on a generated session cookie.
14
+
In this guide, you’ll learn how to configure session persistence for your application. Session persistence ensures that multiple requests from the same client are consistently routed to the same backend Pod. This is useful when your application maintains in-memory state (for example, shopping carts or user sessions). NGINX Gateway Fabric supports configuring session persistence via `UpstreamSettingsPolicy` resource or directly on `HTTPRoute` and `GRPCRoute` resources. For NGINX OSS users, using the `ip_hash` load-balancing method provides basic session affinity by routing requests from the same client IP to the same backend Pod. For NGINX Plus users, cookie-based session persistence can be configured using the `sessionPersistence` field in a Route.
15
15
In this guide, you will deploy three applications:
16
16
17
17
- An application configured with `ip_hash` load-balancing method.
18
-
- An application configured with cookie–based session persistence.
18
+
- An application configured with cookie–based session persistence (if you have access to NGINX Plus).
19
19
- A regular application with default load-balancing.
20
20
21
21
These applications will showcase the benefits of session persistence for stateful workloads.
@@ -152,15 +152,13 @@ kubectl get all -o wide -n default
152
152
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
After creating the Gateway resource, NGINX Gateway Fabric will provision an NGINX Pod and Service fronting it to route traffic. Save the public IP address and port of the NGINX Service into shell variables:
184
+
After creating the Gateway resource, NGINX Gateway Fabric will provision an NGINX Pod and Service fronting it to route traffic. Verify the gateway is created:
185
+
186
+
```bash
187
+
kubectl get gateways.gateway.networking.k8s.io gateway
188
+
```
189
+
190
+
```text
191
+
NAME CLASS ADDRESS PROGRAMMED AGE
192
+
gateway nginx 10.96.15.149 True 23h
193
+
```
194
+
195
+
Save the public IP address and port of the NGINX Service into shell variables:
187
196
188
197
```text
189
198
GW_IP=XXX.YYY.ZZZ.III
@@ -202,7 +211,7 @@ NGINX_POD_NAME=<NGINX Pod>
202
211
203
212
### Session Persistence with NGINX OSS
204
213
205
-
In this section, you’ll configure a basic `coffee` HTTPRoute that routes traffic to the `coffee` Service. You’ll then attach an `UpstreamSettingsPolicy` to change the load-balancing method for that upstream to showcase session affinity behavior. NGINX hashes the client IP to select an upstream server, so requests from the same IP are routed to the same upstream as long as it is available. Session affinity quality with `ip_hash` depends on NGINX seeing the real client IP. In environments with external load balancers or proxies, operators must ensure appropriate `real_ip_header/set_real_ip_from` configuration so that `$remote_addr` reflects the end-user address otherwise, stickiness will be determined by the address of the front-end proxy rather than the actual client. Refer to this [guide]({{< ref "/ngf/how-to/data-plane-configuration/#configure-proxy-protocol-and-rewriteclientip-settings" >}}) for more information on configuring these fields.
214
+
In this section, you’ll configure a basic `coffee` HTTPRoute that routes traffic to the `coffee` Service. You’ll then attach an `UpstreamSettingsPolicy` to change the load-balancing method for that upstream to showcase session affinity behavior. NGINX hashes the client IP to select an upstream server, so requests from the same IP are routed to the same upstream as long as it is available. Session affinity quality with `ip_hash` depends on NGINX seeing the real client IP. In environments with external load balancers or proxies, operators must ensure appropriate `real_ip_header/set_real_ip_from` configuration so that `$remote_addr` reflects the end-user address otherwise, stickiness will be determined by the address of the front-end proxy rather than the actual client.
206
215
207
216
To create an HTTPRoute for the `coffee` service, copy and paste the following into your terminal:
0 commit comments