Skip to content

Commit d2af9e2

Browse files
authored
NGF: Update upstream settings policy guide (#1627)
Update upstream settings policy guide for keepAlive
1 parent c4b744f commit d2af9e2

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

content/ngf/traffic-management/upstream-settings.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,15 @@ You should see the `random two least_time=header` directive on the `coffee` upst
323323
upstream default_coffee_80 {
324324
random two least_time=header;
325325
zone default_coffee_80 1m;
326-
state /var/lib/nginx/state/default_coffee_80.conf;
326+
state /var/lib/nginx/state/default_coffee_80.conf;
327+
keepAlive 16;
327328
}
328329
329330
upstream default_tea_80 {
330331
hash $upstream_addr consistent;
331332
zone default_tea_80 1m;
332333
state /var/lib/nginx/state/default_tea_80.conf;
334+
keepAlive 16;
333335
}
334336
```
335337

@@ -403,19 +405,23 @@ upstream default_coffee_80 {
403405
zone default_coffee_80 1m;
404406
405407
server 10.244.0.14:8080;
408+
keepAlive 16;
406409
}
407410
408411
upstream default_tea_80 {
409412
random two least_conn;
410413
zone default_tea_80 1m;
411414
412415
server 10.244.0.15:8080;
416+
keepAlive 16;
413417
}
414418
```
415419

416420
## Enable keepalive connections
417421

418-
To enable keepalive connections for the `coffee` service, create the following `UpstreamSettingsPolicy`:
422+
By default, the `keepAlive` directive is enabled with a value of 16. You can override this value or disable `keepAlive` entirely by configuring an `UpstreamSettingsPolicy`. To disable keepalive, set the connections field to 0.
423+
424+
The following example creates an `UpstreamSettingsPolicy` that configures keepalive connections for the `coffee` Service with a value of 32:
419425

420426
```yaml
421427
kubectl apply -f - <<EOF
@@ -480,7 +486,54 @@ upstream default_coffee_80 {
480486
}
481487
```
482488

483-
Notice, that the `tea` upstream does not contain the `keepalive` directive, since the `upstream-keepalives` policy does not target the `tea` service:
489+
To disable `keepAlive` directive lets create an `UpstreamSettingsPolicy` targeting the `tea` service with value 0:
490+
491+
```yaml
492+
kubectl apply -f - <<EOF
493+
apiVersion: gateway.nginx.org/v1alpha1
494+
kind: UpstreamSettingsPolicy
495+
metadata:
496+
name: upstream-unset-keepAlive
497+
spec:
498+
targetRefs:
499+
- group: core
500+
kind: Service
501+
name: tea
502+
keepAlive:
503+
connections: 0
504+
EOF
505+
```
506+
507+
Verify that the `UpstreamSettingsPolicy` is Accepted:
508+
509+
```shell
510+
kubectl describe upstreamsettingspolicies.gateway.nginx.org upstream-unset-keepAlive
511+
```
512+
513+
You should see the following status:
514+
515+
```text
516+
Status:
517+
Ancestors:
518+
Ancestor Ref:
519+
Group: gateway.networking.k8s.io
520+
Kind: Gateway
521+
Name: gateway
522+
Namespace: default
523+
Conditions:
524+
Last Transition Time: 2026-01-03T00:35:45Z
525+
Message: The Policy is accepted
526+
Observed Generation: 1
527+
Reason: Accepted
528+
Status: True
529+
Type: Accepted
530+
Controller Name: gateway.nginx.org/nginx-gateway-controller
531+
```
532+
533+
Next, verify that the policy has been applied to the `tea` upstream, by inspecting the NGINX configuration:
534+
535+
```shell
536+
kubectl exec -it -n <NGINX-pod-namespace> $NGINX_POD_NAME -- nginx -T
484537

485538
```text
486539
upstream default_tea_80 {

0 commit comments

Comments
 (0)