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
feat: Document patching dataplane Service, Deployment, DaemonSet in NGF (#862)
Extend the data plane configuration document detailing how to submit custom patches to unblock users who need to set fields that are not yet exposed in the NginxProxy CRD.
Copy file name to clipboardExpand all lines: content/ngf/how-to/data-plane-configuration.md
+116Lines changed: 116 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -375,3 +375,119 @@ To view the full list of configuration options, see the `NginxProxy spec` in the
375
375
376
376
---
377
377
378
+
### Patch data plane Service, Deployment, and DaemonSet
379
+
380
+
NGINX Gateway Fabric supports advanced customization of the data plane Service, Deployment, and DaemonSet objects using patches in the `NginxProxy` resource. This allows you to apply Kubernetes-style patches to these resources, enabling custom labels, annotations, or other modifications that are not directly exposed via the NginxProxy spec.
381
+
382
+
#### Supported Patch Types
383
+
384
+
You can specify one or more patches for each of the following resources:
385
+
386
+
- `spec.kubernetes.service.patches`
387
+
- `spec.kubernetes.deployment.patches`
388
+
- `spec.kubernetes.daemonSet.patches`
389
+
390
+
Each patch has two fields:
391
+
392
+
- `type`: The patch type. Supported values are:
393
+
- `StrategicMerge` (default): Strategic merge patch (Kubernetes default for most resources)
394
+
- `Merge`: JSON merge patch (RFC 7386)
395
+
- `JSONPatch`: JSON patch (RFC 6902)
396
+
- `value`: The patch data. For `StrategicMerge` and `Merge`, this should be a JSON object. For `JSONPatch`, this should be a JSON array of patch operations.
397
+
398
+
Patches are applied in the order they appear in the array. Later patches can override fields set by earlier patches.
399
+
400
+
#### Example: Add a label to the Service
401
+
402
+
```yaml
403
+
apiVersion: gateway.nginx.org/v1alpha2
404
+
kind: NginxProxy
405
+
metadata:
406
+
name: ngf-proxy-patch-service
407
+
spec:
408
+
kubernetes:
409
+
service:
410
+
patches:
411
+
- type: StrategicMerge
412
+
value:
413
+
metadata:
414
+
labels:
415
+
custom-label: "true"
416
+
```
417
+
418
+
#### Example: Patch the Deployment replicas and add an annotation
419
+
420
+
```yaml
421
+
apiVersion: gateway.nginx.org/v1alpha2
422
+
kind: NginxProxy
423
+
metadata:
424
+
name: ngf-proxy-patch-deployment
425
+
spec:
426
+
kubernetes:
427
+
deployment:
428
+
patches:
429
+
- type: Merge
430
+
value:
431
+
metadata:
432
+
annotations:
433
+
custom-annotation: "patched"
434
+
spec:
435
+
replicas: 3
436
+
```
437
+
438
+
#### Example: Use JSONPatch to add a label to the DaemonSet
439
+
440
+
```yaml
441
+
apiVersion: gateway.nginx.org/v1alpha2
442
+
kind: NginxProxy
443
+
metadata:
444
+
name: ngf-proxy-patch-daemonset
445
+
spec:
446
+
kubernetes:
447
+
daemonSet:
448
+
patches:
449
+
- type: JSONPatch
450
+
value:
451
+
- op: add
452
+
path: /metadata/labels/json-patched
453
+
value: "true"
454
+
```
455
+
456
+
#### Example: Multiple patches, later patch overrides earlier
457
+
458
+
```yaml
459
+
apiVersion: gateway.nginx.org/v1alpha2
460
+
kind: NginxProxy
461
+
metadata:
462
+
name: ngf-proxy-multi-patch
463
+
spec:
464
+
kubernetes:
465
+
service:
466
+
patches:
467
+
- type: StrategicMerge
468
+
value:
469
+
metadata:
470
+
labels:
471
+
override-label: "first"
472
+
- type: StrategicMerge
473
+
value:
474
+
metadata:
475
+
labels:
476
+
override-label: "second"
477
+
```
478
+
479
+
In this example, the final Service will have `override-label: second`.
480
+
481
+
{{< note >}}
482
+
**Which patch type should I use?**
483
+
484
+
- **StrategicMerge** is the default and most user-friendly for Kubernetes-native resources like Deployments and Services. It understands lists and merges fields intelligently (e.g., merging containers by name). Use this for most use cases.
485
+
- **Merge** (JSON Merge Patch) is simpler and works well for basic object merges, but does not handle lists or complex merging. Use this if you want to replace entire fields or for non-Kubernetes-native resources.
486
+
- **JSONPatch** is the most powerful and flexible, allowing you to add, remove, or replace specific fields using RFC 6902 operations. Use this for advanced or fine-grained changes, but it is more verbose and error-prone.
487
+
488
+
If unsure, start with StrategicMerge. Use JSONPatch only if you need to surgically modify fields that cannot be addressed by the other patch types.
489
+
490
+
Patches are applied after all other NginxProxy configuration is rendered. Invalid patches will result in a validation error and will not be applied.
0 commit comments