Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e8399d9

Browse files
committedJun 24, 2025·
Add control/data plane HPA
1 parent f8f5fb7 commit e8399d9

29 files changed

+1583
-10082
lines changed
 

‎Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ generate: ## Run go generate
121121

122122
.PHONY: generate-crds
123123
generate-crds: ## Generate CRDs and Go types using kubebuilder
124-
go run sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) crd object paths=./apis/... output:crd:artifacts:config=config/crd/bases
124+
go run sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) crd:maxDescLen=0 object paths=./apis/... output:crd:artifacts:config=config/crd/bases
125125
kubectl kustomize config/crd >deploy/crds.yaml
126126

127127
.PHONY: install-crds

‎apis/v1alpha2/nginxproxy_types.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1alpha2
22

33
import (
4+
autoscalingv2 "k8s.io/api/autoscaling/v2"
45
corev1 "k8s.io/api/core/v1"
56
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
67

@@ -388,6 +389,11 @@ type DeploymentSpec struct {
388389
// +optional
389390
Replicas *int32 `json:"replicas,omitempty"`
390391

392+
// Horizontal Pod Autoscaling.
393+
//
394+
// +optional
395+
Autoscaling HPASpec `json:"autoscaling"`
396+
391397
// Pod defines Pod-specific fields.
392398
//
393399
// +optional
@@ -412,6 +418,47 @@ type DaemonSetSpec struct {
412418
Container ContainerSpec `json:"container"`
413419
}
414420

421+
type HPASpec struct {
422+
// Enable or disable Horizontal Pod Autoscaler
423+
Enabled bool `json:"enabled"`
424+
425+
// Annotation for Horizontal Pod Autoscaler
426+
// Annotations is an unstructured key value map stored with a resource that may be
427+
// set by external tools to store and retrieve arbitrary metadata. They are not
428+
// queryable and should be preserved when modifying objects.
429+
// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations
430+
// +optional
431+
HPAAnnotations map[string]string `json:"hpaAnnotations,omitempty"`
432+
433+
// Minimun of replicas.
434+
MinReplicas int32 `json:"minReplicas"`
435+
436+
// Minimun of replicas.
437+
MaxReplicas int32 `json:"maxReplicas"`
438+
439+
// Target cpu utilization percentage of HPA.
440+
//
441+
// +optional
442+
TargetCPUUtilizationPercentage *int32 `json:"targetCPUUtilizationPercentage,omitempty"`
443+
444+
// Target memory utilization percentage of HPA.
445+
//
446+
// +optional
447+
TargetMemoryUtilizationPercentage *int32 `json:"targetMemoryUtilizationPercentage,omitempty"`
448+
449+
// behavior configures the scaling behavior of the target
450+
// in both Up and Down directions (scaleUp and scaleDown fields respectively).
451+
// If not set, the default HPAScalingRules for scale up and scale down are used.
452+
//
453+
// +optional
454+
Behavior *autoscalingv2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"`
455+
456+
// AutoscalingTemplate configures the addtional scaling option.
457+
//
458+
// +optional
459+
AutoscalingTemplate *[]autoscalingv2.MetricSpec `json:"autoscalingTemplate,omitempty"`
460+
}
461+
415462
// PodSpec defines Pod-specific fields.
416463
type PodSpec struct {
417464
// TerminationGracePeriodSeconds is the optional duration in seconds the pod needs to terminate gracefully.

‎apis/v1alpha2/zz_generated.deepcopy.go

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎charts/nginx-gateway-fabric/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,18 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
264264
| `certGenerator.ttlSecondsAfterFinished` | How long to wait after the cert generator job has finished before it is removed by the job controller. | int | `30` |
265265
| `clusterDomain` | The DNS cluster domain of your Kubernetes cluster. | string | `"cluster.local"` |
266266
| `gateways` | A list of Gateway objects. View https://gateway-api.sigs.k8s.io/reference/spec/#gateway for full Gateway reference. | list | `[]` |
267-
| `nginx` | The nginx section contains the configuration for all NGINX data plane deployments installed by the NGINX Gateway Fabric control plane. | object | `{"config":{},"container":{},"debug":false,"image":{"pullPolicy":"Always","repository":"ghcr.io/nginx/nginx-gateway-fabric/nginx","tag":"edge"},"imagePullSecret":"","imagePullSecrets":[],"kind":"deployment","plus":false,"pod":{},"replicas":1,"service":{"externalTrafficPolicy":"Local","loadBalancerClass":"","loadBalancerIP":"","loadBalancerSourceRanges":[],"nodePorts":[],"type":"LoadBalancer"},"usage":{"caSecretName":"","clientSSLSecretName":"","endpoint":"","resolver":"","secretName":"nplus-license","skipVerify":false}}` |
267+
| `nginx` | The nginx section contains the configuration for all NGINX data plane deployments installed by the NGINX Gateway Fabric control plane. | object | `{"autoscaling":{"behavior":{"scaleDown":{"policies":[{"periodSeconds":180,"type":"Pods","value":1}],"stabilizationWindowSeconds":300},"scaleUp":{"policies":[{"periodSeconds":60,"type":"Pods","value":2}],"stabilizationWindowSeconds":300}},"enabled":true,"hpaAnnotations":{},"maxReplicas":11,"minReplicas":1,"targetCPUUtilizationPercentage":50,"targetMemoryUtilizationPercentage":50},"autoscalingTemplate":[],"config":{},"container":{"resources":{}},"debug":false,"image":{"pullPolicy":"Always","repository":"ghcr.io/nginx/nginx-gateway-fabric/nginx","tag":"edge"},"imagePullSecret":"","imagePullSecrets":[],"kind":"deployment","plus":false,"pod":{"tolerations":[]},"replicas":1,"service":{"externalTrafficPolicy":"Local","loadBalancerClass":"","loadBalancerIP":"","loadBalancerSourceRanges":[],"nodePorts":[],"type":"LoadBalancer"},"usage":{"caSecretName":"","clientSSLSecretName":"","endpoint":"","resolver":"","secretName":"nplus-license","skipVerify":false}}` |
268268
| `nginx.config` | The configuration for the data plane that is contained in the NginxProxy resource. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{}` |
269-
| `nginx.container` | The container configuration for the NGINX container. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{}` |
269+
| `nginx.container` | The container configuration for the NGINX container. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{"resources":{}}` |
270+
| `nginx.container.resources` | The resource requirements of the NGINX container. You should be set this value, If you want to use dataplane Autoscaling(HPA). | object | `{}` |
270271
| `nginx.debug` | Enable debugging for NGINX. Uses the nginx-debug binary. The NGINX error log level should be set to debug in the NginxProxy resource. | bool | `false` |
271272
| `nginx.image.repository` | The NGINX image to use. | string | `"ghcr.io/nginx/nginx-gateway-fabric/nginx"` |
272273
| `nginx.imagePullSecret` | The name of the secret containing docker registry credentials. Secret must exist in the same namespace as the helm release. The control plane will copy this secret into any namespace where NGINX is deployed. | string | `""` |
273274
| `nginx.imagePullSecrets` | A list of secret names containing docker registry credentials. Secrets must exist in the same namespace as the helm release. The control plane will copy these secrets into any namespace where NGINX is deployed. | list | `[]` |
274275
| `nginx.kind` | The kind of NGINX deployment. | string | `"deployment"` |
275276
| `nginx.plus` | Is NGINX Plus image being used. | bool | `false` |
276-
| `nginx.pod` | The pod configuration for the NGINX data plane pod. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{}` |
277+
| `nginx.pod` | The pod configuration for the NGINX data plane pod. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{"tolerations":[]}` |
278+
| `nginx.pod.tolerations` | Tolerations for the NGINX data plane pod. | list | `[]` |
277279
| `nginx.replicas` | The number of replicas of the NGINX Deployment. | int | `1` |
278280
| `nginx.service` | The service configuration for the NGINX data plane. This is applied globally to all Gateways managed by this instance of NGINX Gateway Fabric. | object | `{"externalTrafficPolicy":"Local","loadBalancerClass":"","loadBalancerIP":"","loadBalancerSourceRanges":[],"nodePorts":[],"type":"LoadBalancer"}` |
279281
| `nginx.service.externalTrafficPolicy` | The externalTrafficPolicy of the service. The value Local preserves the client source IP. | string | `"Local"` |
@@ -288,7 +290,7 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
288290
| `nginx.usage.resolver` | The nameserver used to resolve the NGINX Plus usage reporting endpoint. Used with NGINX Instance Manager. | string | `""` |
289291
| `nginx.usage.secretName` | The name of the Secret containing the JWT for NGINX Plus usage reporting. Must exist in the same namespace that the NGINX Gateway Fabric control plane is running in (default namespace: nginx-gateway). | string | `"nplus-license"` |
290292
| `nginx.usage.skipVerify` | Disable client verification of the NGINX Plus usage reporting server certificate. | bool | `false` |
291-
| `nginxGateway` | The nginxGateway section contains configuration for the NGINX Gateway Fabric control plane deployment. | object | `{"affinity":{},"config":{"logging":{"level":"info"}},"configAnnotations":{},"extraVolumeMounts":[],"extraVolumes":[],"gatewayClassAnnotations":{},"gatewayClassName":"nginx","gatewayControllerName":"gateway.nginx.org/nginx-gateway-controller","gwAPIExperimentalFeatures":{"enable":false},"image":{"pullPolicy":"Always","repository":"ghcr.io/nginx/nginx-gateway-fabric","tag":"edge"},"kind":"deployment","labels":{},"leaderElection":{"enable":true,"lockName":""},"lifecycle":{},"metrics":{"enable":true,"port":9113,"secure":false},"name":"","nodeSelector":{},"podAnnotations":{},"productTelemetry":{"enable":true},"readinessProbe":{"enable":true,"initialDelaySeconds":3,"port":8081},"replicas":1,"resources":{},"service":{"annotations":{},"labels":{}},"serviceAccount":{"annotations":{},"imagePullSecret":"","imagePullSecrets":[],"name":""},"snippetsFilters":{"enable":false},"terminationGracePeriodSeconds":30,"tolerations":[],"topologySpreadConstraints":[]}` |
293+
| `nginxGateway` | The nginxGateway section contains configuration for the NGINX Gateway Fabric control plane deployment. | object | `{"affinity":{},"autoscaling":{"annotations":{},"behavior":{},"enabled":false,"maxReplicas":11,"minReplicas":1,"targetCPUUtilizationPercentage":50,"targetMemoryUtilizationPercentage":50},"autoscalingTemplate":[],"config":{"logging":{"level":"info"}},"configAnnotations":{},"extraVolumeMounts":[],"extraVolumes":[],"gatewayClassAnnotations":{},"gatewayClassName":"nginx","gatewayControllerName":"gateway.nginx.org/nginx-gateway-controller","gwAPIExperimentalFeatures":{"enable":false},"image":{"pullPolicy":"Always","repository":"ghcr.io/nginx/nginx-gateway-fabric","tag":"edge"},"kind":"deployment","labels":{},"leaderElection":{"enable":true,"lockName":""},"lifecycle":{},"metrics":{"enable":true,"port":9113,"secure":false},"nodeSelector":{},"podAnnotations":{},"productTelemetry":{"enable":true},"readinessProbe":{"enable":true,"initialDelaySeconds":3,"port":8081},"replicas":1,"resources":{},"service":{"annotations":{},"labels":{}},"serviceAccount":{"annotations":{},"imagePullSecret":"","imagePullSecrets":[],"name":""},"snippetsFilters":{"enable":false},"terminationGracePeriodSeconds":30,"tolerations":[],"topologySpreadConstraints":[]}` |
292294
| `nginxGateway.affinity` | The affinity of the NGINX Gateway Fabric control plane pod. | object | `{}` |
293295
| `nginxGateway.config.logging.level` | Log level. | string | `"info"` |
294296
| `nginxGateway.configAnnotations` | Set of custom annotations for NginxGateway objects. | object | `{}` |
@@ -308,7 +310,6 @@ The following table lists the configurable parameters of the NGINX Gateway Fabri
308310
| `nginxGateway.metrics.enable` | Enable exposing metrics in the Prometheus format. | bool | `true` |
309311
| `nginxGateway.metrics.port` | Set the port where the Prometheus metrics are exposed. | int | `9113` |
310312
| `nginxGateway.metrics.secure` | Enable serving metrics via https. By default metrics are served via http. Please note that this endpoint will be secured with a self-signed certificate. | bool | `false` |
311-
| `nginxGateway.name` | The name of the NGINX Gateway Fabric deployment - if not present, then by default uses release name given during installation. | string | `""` |
312313
| `nginxGateway.nodeSelector` | The nodeSelector of the NGINX Gateway Fabric control plane pod. | object | `{}` |
313314
| `nginxGateway.podAnnotations` | Set of custom annotations for the NGINX Gateway Fabric pods. | object | `{}` |
314315
| `nginxGateway.productTelemetry.enable` | Enable the collection of product telemetry. | bool | `true` |

‎charts/nginx-gateway-fabric/templates/clusterrole.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ rules:
88
- apiGroups:
99
- ""
1010
- apps
11+
- autoscaling
1112
resources:
1213
- secrets
1314
- configmaps
1415
- serviceaccounts
1516
- services
1617
- deployments
1718
- daemonsets
19+
- horizontalpodautoscalers
1820
verbs:
1921
- create
2022
- update
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{{- if and (eq .Values.nginxGateway.kind "deployment") .Values.nginxGateway.autoscaling.enabled -}}
2+
apiVersion: {{ ternary "autoscaling/v2" "autoscaling/v2beta2" (.Capabilities.APIVersions.Has "autoscaling/v2") }}
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
{{- with .Values.nginxGateway.autoscaling.annotations }}
6+
annotations: {{ toYaml . | nindent 4 }}
7+
{{- end }}
8+
labels:
9+
{{- include "nginx-gateway.labels" . | nindent 4 }}
10+
{{- with .Values.nginxGateway.labels }}
11+
{{- toYaml . | nindent 4 }}
12+
{{- end }}
13+
name: {{ include "nginx-gateway.fullname" . }}
14+
namespace: {{ .Release.Namespace }}
15+
spec:
16+
scaleTargetRef:
17+
apiVersion: apps/v1
18+
kind: Deployment
19+
name: {{ include "nginx-gateway.fullname" . }}
20+
minReplicas: {{ .Values.nginxGateway.autoscaling.minReplicas }}
21+
maxReplicas: {{ .Values.nginxGateway.autoscaling.maxReplicas }}
22+
metrics:
23+
{{- with .Values.nginxGateway.autoscaling.targetMemoryUtilizationPercentage }}
24+
- type: Resource
25+
resource:
26+
name: memory
27+
target:
28+
type: Utilization
29+
averageUtilization: {{ . }}
30+
{{- end }}
31+
{{- with .Values.nginxGateway.autoscaling.targetCPUUtilizationPercentage }}
32+
- type: Resource
33+
resource:
34+
name: cpu
35+
target:
36+
type: Utilization
37+
averageUtilization: {{ . }}
38+
{{- end }}
39+
{{- with .Values.autoscalingTemplate }}
40+
{{- toYaml . | nindent 2 }}
41+
{{- end }}
42+
{{- with .Values.nginxGateway.autoscaling.behavior }}
43+
behavior:
44+
{{- toYaml . | nindent 4 }}
45+
{{- end }}
46+
{{- end }}

‎charts/nginx-gateway-fabric/templates/nginxproxy.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,27 @@ spec:
1212
kubernetes:
1313
{{- if eq .Values.nginx.kind "deployment" }}
1414
deployment:
15+
{{- if .Values.nginx.replicas }}
1516
replicas: {{ .Values.nginx.replicas }}
17+
{{- end }}
18+
autoscaling:
19+
enabled: {{ .Values.nginx.autoscaling.enabled }}
20+
{{- if .Values.nginx.autoscaling.hpaAnnotations }}
21+
hpaAnnotations:
22+
{{- toYaml .Values.nginx.autoscaling.hpaAnnotations | nindent 10 }}
23+
{{- end }}
24+
minReplicas: {{ .Values.nginx.autoscaling.minReplicas }}
25+
maxReplicas: {{ .Values.nginx.autoscaling.maxReplicas }}
26+
targetCPUUtilizationPercentage: {{ .Values.nginx.autoscaling.targetCPUUtilizationPercentage }}
27+
targetMemoryUtilizationPercentage: {{ .Values.nginx.autoscaling.targetMemoryUtilizationPercentage }}
28+
{{- if .Values.nginx.autoscaling.behavior }}
29+
behavior:
30+
{{- toYaml .Values.nginx.autoscaling.behavior | nindent 10 }}
31+
{{- end }}
32+
{{- if .Values.nginx.autoscalingTemplate }}
33+
autoscalingTemplate:
34+
{{- toYaml .Values.nginx.autoscalingTemplate | nindent 8 }}
35+
{{- end }}
1636
{{- if .Values.nginx.pod }}
1737
pod:
1838
{{- toYaml .Values.nginx.pod | nindent 8 }}

‎charts/nginx-gateway-fabric/values.schema.json

Lines changed: 228 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,158 @@
9898
"nginx": {
9999
"description": "The nginx section contains the configuration for all NGINX data plane deployments\ninstalled by the NGINX Gateway Fabric control plane.",
100100
"properties": {
101+
"autoscaling": {
102+
"properties": {
103+
"behavior": {
104+
"properties": {
105+
"scaleDown": {
106+
"properties": {
107+
"policies": {
108+
"items": {
109+
"anyOf": [
110+
{
111+
"properties": {
112+
"periodSeconds": {
113+
"default": 180,
114+
"required": [],
115+
"title": "periodSeconds",
116+
"type": "integer"
117+
},
118+
"type": {
119+
"default": "Pods",
120+
"required": [],
121+
"title": "type",
122+
"type": "string"
123+
},
124+
"value": {
125+
"default": 1,
126+
"required": [],
127+
"title": "value",
128+
"type": "integer"
129+
}
130+
},
131+
"required": [],
132+
"type": "object"
133+
}
134+
],
135+
"required": []
136+
},
137+
"required": [],
138+
"title": "policies",
139+
"type": "array"
140+
},
141+
"stabilizationWindowSeconds": {
142+
"default": 300,
143+
"required": [],
144+
"title": "stabilizationWindowSeconds",
145+
"type": "integer"
146+
}
147+
},
148+
"required": [],
149+
"title": "scaleDown",
150+
"type": "object"
151+
},
152+
"scaleUp": {
153+
"properties": {
154+
"policies": {
155+
"items": {
156+
"anyOf": [
157+
{
158+
"properties": {
159+
"periodSeconds": {
160+
"default": 60,
161+
"required": [],
162+
"title": "periodSeconds",
163+
"type": "integer"
164+
},
165+
"type": {
166+
"default": "Pods",
167+
"required": [],
168+
"title": "type",
169+
"type": "string"
170+
},
171+
"value": {
172+
"default": 2,
173+
"required": [],
174+
"title": "value",
175+
"type": "integer"
176+
}
177+
},
178+
"required": [],
179+
"type": "object"
180+
}
181+
],
182+
"required": []
183+
},
184+
"required": [],
185+
"title": "policies",
186+
"type": "array"
187+
},
188+
"stabilizationWindowSeconds": {
189+
"default": 300,
190+
"required": [],
191+
"title": "stabilizationWindowSeconds",
192+
"type": "integer"
193+
}
194+
},
195+
"required": [],
196+
"title": "scaleUp",
197+
"type": "object"
198+
}
199+
},
200+
"required": [],
201+
"title": "behavior",
202+
"type": "object"
203+
},
204+
"enabled": {
205+
"default": true,
206+
"description": "Enable or disable Horizontal Pod Autoscaler",
207+
"required": [],
208+
"title": "enabled",
209+
"type": "boolean"
210+
},
211+
"hpaAnnotations": {
212+
"required": [],
213+
"title": "hpaAnnotations",
214+
"type": "object"
215+
},
216+
"maxReplicas": {
217+
"default": 11,
218+
"required": [],
219+
"title": "maxReplicas",
220+
"type": "integer"
221+
},
222+
"minReplicas": {
223+
"default": 1,
224+
"required": [],
225+
"title": "minReplicas",
226+
"type": "integer"
227+
},
228+
"targetCPUUtilizationPercentage": {
229+
"default": 50,
230+
"required": [],
231+
"title": "targetCPUUtilizationPercentage",
232+
"type": "integer"
233+
},
234+
"targetMemoryUtilizationPercentage": {
235+
"default": 50,
236+
"required": [],
237+
"title": "targetMemoryUtilizationPercentage",
238+
"type": "integer"
239+
}
240+
},
241+
"required": [],
242+
"title": "autoscaling",
243+
"type": "object"
244+
},
245+
"autoscalingTemplate": {
246+
"items": {
247+
"required": []
248+
},
249+
"required": [],
250+
"title": "autoscalingTemplate",
251+
"type": "array"
252+
},
101253
"config": {
102254
"description": "The configuration for the data plane that is contained in the NginxProxy resource. This is applied globally to all Gateways\nmanaged by this instance of NGINX Gateway Fabric.",
103255
"properties": {
@@ -313,6 +465,14 @@
313465
},
314466
"container": {
315467
"description": "The container configuration for the NGINX container. This is applied globally to all Gateways managed by this\ninstance of NGINX Gateway Fabric.",
468+
"properties": {
469+
"resources": {
470+
"description": "The resource requirements of the NGINX container. You should be set this value, If you want to use dataplane Autoscaling(HPA).",
471+
"required": [],
472+
"title": "resources",
473+
"type": "object"
474+
}
475+
},
316476
"required": [],
317477
"title": "container",
318478
"type": "object"
@@ -325,6 +485,7 @@
325485
"type": "boolean"
326486
},
327487
"image": {
488+
"description": "Custom or additional autoscaling metrics\nref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics\n- type: Pods\n pods:\n metric:\n name: nginx_gateway_fabric_nginx_process_requests_total\n target:\n type: AverageValue\n averageValue: 10000m",
328489
"properties": {
329490
"pullPolicy": {
330491
"default": "Always",
@@ -389,6 +550,17 @@
389550
},
390551
"pod": {
391552
"description": "The pod configuration for the NGINX data plane pod. This is applied globally to all Gateways managed by this\ninstance of NGINX Gateway Fabric.",
553+
"properties": {
554+
"tolerations": {
555+
"description": "Tolerations for the NGINX data plane pod.",
556+
"items": {
557+
"required": []
558+
},
559+
"required": [],
560+
"title": "tolerations",
561+
"type": "array"
562+
}
563+
},
392564
"required": [],
393565
"title": "pod",
394566
"type": "object"
@@ -540,6 +712,62 @@
540712
"title": "affinity",
541713
"type": "object"
542714
},
715+
"autoscaling": {
716+
"properties": {
717+
"annotations": {
718+
"required": [],
719+
"title": "annotations",
720+
"type": "object"
721+
},
722+
"behavior": {
723+
"required": [],
724+
"title": "behavior",
725+
"type": "object"
726+
},
727+
"enabled": {
728+
"default": false,
729+
"description": "Enable or disable Horizontal Pod Autoscaler",
730+
"required": [],
731+
"title": "enabled",
732+
"type": "boolean"
733+
},
734+
"maxReplicas": {
735+
"default": 11,
736+
"required": [],
737+
"title": "maxReplicas",
738+
"type": "integer"
739+
},
740+
"minReplicas": {
741+
"default": 1,
742+
"required": [],
743+
"title": "minReplicas",
744+
"type": "integer"
745+
},
746+
"targetCPUUtilizationPercentage": {
747+
"default": 50,
748+
"required": [],
749+
"title": "targetCPUUtilizationPercentage",
750+
"type": "integer"
751+
},
752+
"targetMemoryUtilizationPercentage": {
753+
"default": 50,
754+
"required": [],
755+
"title": "targetMemoryUtilizationPercentage",
756+
"type": "integer"
757+
}
758+
},
759+
"required": [],
760+
"title": "autoscaling",
761+
"type": "object"
762+
},
763+
"autoscalingTemplate": {
764+
"items": {
765+
"required": []
766+
},
767+
"required": [],
768+
"title": "autoscalingTemplate",
769+
"type": "array"
770+
},
543771
"config": {
544772
"description": "The dynamic configuration for the control plane that is contained in the NginxGateway resource.",
545773
"properties": {
@@ -726,13 +954,6 @@
726954
"title": "metrics",
727955
"type": "object"
728956
},
729-
"name": {
730-
"default": "",
731-
"description": "The name of the NGINX Gateway Fabric deployment - if not present, then by default uses release name given during installation.",
732-
"required": [],
733-
"title": "name",
734-
"type": "string"
735-
},
736957
"nodeSelector": {
737958
"description": "The nodeSelector of the NGINX Gateway Fabric control plane pod.",
738959
"required": [],

‎charts/nginx-gateway-fabric/values.yaml

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ nginxGateway:
1313
# -- The kind of the NGINX Gateway Fabric installation - currently, only deployment is supported.
1414
kind: deployment
1515

16-
# -- The name of the NGINX Gateway Fabric deployment - if not present, then by default uses release name given during installation.
17-
name: ""
18-
1916
# @schema
2017
# required: true
2118
# type: string
@@ -159,6 +156,38 @@ nginxGateway:
159156
# -- The topology spread constraints for the NGINX Gateway Fabric control plane pod.
160157
topologySpreadConstraints: []
161158

159+
autoscaling:
160+
# Enable or disable Horizontal Pod Autoscaler
161+
enabled: false
162+
annotations: {}
163+
minReplicas: 1
164+
maxReplicas: 11
165+
targetCPUUtilizationPercentage: 50
166+
targetMemoryUtilizationPercentage: 50
167+
behavior: {}
168+
# scaleDown:
169+
# stabilizationWindowSeconds: 300
170+
# policies:
171+
# - type: Pods
172+
# value: 1
173+
# periodSeconds: 180
174+
# scaleUp:
175+
# stabilizationWindowSeconds: 300
176+
# policies:
177+
# - type: Pods
178+
# value: 2
179+
# periodSeconds: 60
180+
autoscalingTemplate: []
181+
# Custom or additional autoscaling metrics
182+
# ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics
183+
# - type: Pods
184+
# pods:
185+
# metric:
186+
# name: nginx_gateway_fabric_nginx_process_requests_total
187+
# target:
188+
# type: AverageValue
189+
# averageValue: 10000m
190+
162191
metrics:
163192
# -- Enable exposing metrics in the Prometheus format.
164193
enable: true
@@ -199,6 +228,37 @@ nginx:
199228
# -- The number of replicas of the NGINX Deployment.
200229
replicas: 1
201230

231+
autoscaling:
232+
# Enable or disable Horizontal Pod Autoscaler
233+
enabled: true
234+
hpaAnnotations: {}
235+
minReplicas: 1
236+
maxReplicas: 11
237+
targetCPUUtilizationPercentage: 50
238+
targetMemoryUtilizationPercentage: 50
239+
behavior:
240+
scaleDown:
241+
stabilizationWindowSeconds: 300
242+
policies:
243+
- type: Pods
244+
value: 1
245+
periodSeconds: 180
246+
scaleUp:
247+
stabilizationWindowSeconds: 300
248+
policies:
249+
- type: Pods
250+
value: 2
251+
periodSeconds: 60
252+
autoscalingTemplate: []
253+
# Custom or additional autoscaling metrics
254+
# ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-custom-metrics
255+
# - type: Pods
256+
# pods:
257+
# metric:
258+
# name: nginx_gateway_fabric_nginx_process_requests_total
259+
# target:
260+
# type: AverageValue
261+
# averageValue: 10000m
202262
image:
203263
# -- The NGINX image to use.
204264
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
@@ -380,12 +440,12 @@ nginx:
380440

381441
# -- The pod configuration for the NGINX data plane pod. This is applied globally to all Gateways managed by this
382442
# instance of NGINX Gateway Fabric.
383-
pod: {}
443+
pod:
384444
# -- The termination grace period of the NGINX data plane pod.
385445
# terminationGracePeriodSeconds: 30
386446

387447
# -- Tolerations for the NGINX data plane pod.
388-
# tolerations: []
448+
tolerations: []
389449

390450
# -- The nodeSelector of the NGINX data plane pod.
391451
# nodeSelector: {}
@@ -402,9 +462,10 @@ nginx:
402462

403463
# -- The container configuration for the NGINX container. This is applied globally to all Gateways managed by this
404464
# instance of NGINX Gateway Fabric.
405-
container: {}
406-
# -- The resource requirements of the NGINX container.
407-
# resources: {}
465+
container:
466+
# -- The resource requirements of the NGINX container. You should be set this value, If you want to use dataplane Autoscaling(HPA).
467+
resources: {}
468+
408469

409470
# -- The lifecycle of the NGINX container.
410471
# lifecycle: {}

‎config/crd/bases/gateway.nginx.org_clientsettingspolicies.yaml

Lines changed: 0 additions & 253 deletions
Large diffs are not rendered by default.

‎config/crd/bases/gateway.nginx.org_nginxgateways.yaml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,19 @@ spec:
2323
name: v1alpha1
2424
schema:
2525
openAPIV3Schema:
26-
description: NginxGateway represents the dynamic configuration for an NGINX
27-
Gateway Fabric control plane.
2826
properties:
2927
apiVersion:
30-
description: |-
31-
APIVersion defines the versioned schema of this representation of an object.
32-
Servers should convert recognized schemas to the latest internal value, and
33-
may reject unrecognized values.
34-
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
3528
type: string
3629
kind:
37-
description: |-
38-
Kind is a string value representing the REST resource this object represents.
39-
Servers may infer this from the endpoint the client submits requests to.
40-
Cannot be updated.
41-
In CamelCase.
42-
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
4330
type: string
4431
metadata:
4532
type: object
4633
spec:
47-
description: NginxGatewaySpec defines the desired state of the NginxGateway.
4834
properties:
4935
logging:
50-
description: Logging defines logging related settings for the control
51-
plane.
5236
properties:
5337
level:
5438
default: info
55-
description: Level defines the logging level.
5639
enum:
5740
- info
5841
- debug
@@ -61,53 +44,32 @@ spec:
6144
type: object
6245
type: object
6346
status:
64-
description: NginxGatewayStatus defines the state of the NginxGateway.
6547
properties:
6648
conditions:
6749
items:
68-
description: Condition contains details for one aspect of the current
69-
state of this API Resource.
7050
properties:
7151
lastTransitionTime:
72-
description: |-
73-
lastTransitionTime is the last time the condition transitioned from one status to another.
74-
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
7552
format: date-time
7653
type: string
7754
message:
78-
description: |-
79-
message is a human readable message indicating details about the transition.
80-
This may be an empty string.
8155
maxLength: 32768
8256
type: string
8357
observedGeneration:
84-
description: |-
85-
observedGeneration represents the .metadata.generation that the condition was set based upon.
86-
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
87-
with respect to the current state of the instance.
8858
format: int64
8959
minimum: 0
9060
type: integer
9161
reason:
92-
description: |-
93-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
94-
Producers of specific condition types may define expected values and meanings for this field,
95-
and whether the values are considered a guaranteed API.
96-
The value should be a CamelCase string.
97-
This field may not be empty.
9862
maxLength: 1024
9963
minLength: 1
10064
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
10165
type: string
10266
status:
103-
description: status of the condition, one of True, False, Unknown.
10467
enum:
10568
- "True"
10669
- "False"
10770
- Unknown
10871
type: string
10972
type:
110-
description: type of condition in CamelCase or in foo.example.com/CamelCase.
11173
maxLength: 316
11274
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
11375
type: string

‎config/crd/bases/gateway.nginx.org_nginxproxies.yaml

Lines changed: 360 additions & 3910 deletions
Large diffs are not rendered by default.

‎config/crd/bases/gateway.nginx.org_observabilitypolicies.yaml

Lines changed: 0 additions & 511 deletions
Large diffs are not rendered by default.

‎config/crd/bases/gateway.nginx.org_snippetsfilters.yaml

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,26 @@ spec:
2525
name: v1alpha1
2626
schema:
2727
openAPIV3Schema:
28-
description: |-
29-
SnippetsFilter is a filter that allows inserting NGINX configuration into the
30-
generated NGINX config for HTTPRoute and GRPCRoute resources.
3128
properties:
3229
apiVersion:
33-
description: |-
34-
APIVersion defines the versioned schema of this representation of an object.
35-
Servers should convert recognized schemas to the latest internal value, and
36-
may reject unrecognized values.
37-
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
3830
type: string
3931
kind:
40-
description: |-
41-
Kind is a string value representing the REST resource this object represents.
42-
Servers may infer this from the endpoint the client submits requests to.
43-
Cannot be updated.
44-
In CamelCase.
45-
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
4632
type: string
4733
metadata:
4834
type: object
4935
spec:
50-
description: Spec defines the desired state of the SnippetsFilter.
5136
properties:
5237
snippets:
53-
description: |-
54-
Snippets is a list of NGINX configuration snippets.
55-
There can only be one snippet per context.
56-
Allowed contexts: main, http, http.server, http.server.location.
5738
items:
58-
description: Snippet represents an NGINX configuration snippet.
5939
properties:
6040
context:
61-
description: Context is the NGINX context to insert the snippet
62-
into.
6341
enum:
6442
- main
6543
- http
6644
- http.server
6745
- http.server.location
6846
type: string
6947
value:
70-
description: Value is the NGINX configuration snippet.
7148
minLength: 1
7249
type: string
7350
required:
@@ -84,61 +61,35 @@ spec:
8461
- snippets
8562
type: object
8663
status:
87-
description: Status defines the state of the SnippetsFilter.
8864
properties:
8965
controllers:
90-
description: |-
91-
Controllers is a list of Gateway API controllers that processed the SnippetsFilter
92-
and the status of the SnippetsFilter with respect to each controller.
9366
items:
9467
properties:
9568
conditions:
96-
description: Conditions describe the status of the SnippetsFilter.
9769
items:
98-
description: Condition contains details for one aspect of
99-
the current state of this API Resource.
10070
properties:
10171
lastTransitionTime:
102-
description: |-
103-
lastTransitionTime is the last time the condition transitioned from one status to another.
104-
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
10572
format: date-time
10673
type: string
10774
message:
108-
description: |-
109-
message is a human readable message indicating details about the transition.
110-
This may be an empty string.
11175
maxLength: 32768
11276
type: string
11377
observedGeneration:
114-
description: |-
115-
observedGeneration represents the .metadata.generation that the condition was set based upon.
116-
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
117-
with respect to the current state of the instance.
11878
format: int64
11979
minimum: 0
12080
type: integer
12181
reason:
122-
description: |-
123-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
124-
Producers of specific condition types may define expected values and meanings for this field,
125-
and whether the values are considered a guaranteed API.
126-
The value should be a CamelCase string.
127-
This field may not be empty.
12882
maxLength: 1024
12983
minLength: 1
13084
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
13185
type: string
13286
status:
133-
description: status of the condition, one of True, False,
134-
Unknown.
13587
enum:
13688
- "True"
13789
- "False"
13890
- Unknown
13991
type: string
14092
type:
141-
description: type of condition in CamelCase or in foo.example.com/CamelCase.
14293
maxLength: 316
14394
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
14495
type: string
@@ -156,20 +107,6 @@ spec:
156107
- type
157108
x-kubernetes-list-type: map
158109
controllerName:
159-
description: |-
160-
ControllerName is a domain/path string that indicates the name of the
161-
controller that wrote this status. This corresponds with the
162-
controllerName field on GatewayClass.
163-
164-
Example: "example.net/gateway-controller".
165-
166-
The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are
167-
valid Kubernetes names
168-
(https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names).
169-
170-
Controllers MUST populate this field when writing status. Controllers should ensure that
171-
entries to status populated with their ControllerName are cleaned up when they are no
172-
longer necessary.
173110
maxLength: 253
174111
minLength: 1
175112
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[A-Za-z0-9\/\-._~%!$&'()*+,;=:]+$

‎config/crd/bases/gateway.nginx.org_upstreamsettingspolicies.yaml

Lines changed: 0 additions & 254 deletions
Large diffs are not rendered by default.

‎deploy/azure/deploy.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -410,14 +412,35 @@ metadata:
410412
spec:
411413
kubernetes:
412414
deployment:
415+
autoscaling:
416+
behavior:
417+
scaleDown:
418+
policies:
419+
- periodSeconds: 180
420+
type: Pods
421+
value: 1
422+
stabilizationWindowSeconds: 300
423+
scaleUp:
424+
policies:
425+
- periodSeconds: 60
426+
type: Pods
427+
value: 2
428+
stabilizationWindowSeconds: 300
429+
enabled: true
430+
maxReplicas: 11
431+
minReplicas: 1
432+
targetCPUUtilizationPercentage: 50
433+
targetMemoryUtilizationPercentage: 50
413434
container:
414435
image:
415436
pullPolicy: Always
416437
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
417438
tag: edge
439+
resources: {}
418440
pod:
419441
nodeSelector:
420442
kubernetes.io/os: linux
443+
tolerations: []
421444
replicas: 1
422445
service:
423446
externalTrafficPolicy: Local

‎deploy/crds.yaml

Lines changed: 360 additions & 5029 deletions
Large diffs are not rendered by default.

‎deploy/default/deploy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -408,11 +410,33 @@ metadata:
408410
spec:
409411
kubernetes:
410412
deployment:
413+
autoscaling:
414+
behavior:
415+
scaleDown:
416+
policies:
417+
- periodSeconds: 180
418+
type: Pods
419+
value: 1
420+
stabilizationWindowSeconds: 300
421+
scaleUp:
422+
policies:
423+
- periodSeconds: 60
424+
type: Pods
425+
value: 2
426+
stabilizationWindowSeconds: 300
427+
enabled: true
428+
maxReplicas: 11
429+
minReplicas: 1
430+
targetCPUUtilizationPercentage: 50
431+
targetMemoryUtilizationPercentage: 50
411432
container:
412433
image:
413434
pullPolicy: Always
414435
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
415436
tag: edge
437+
resources: {}
438+
pod:
439+
tolerations: []
416440
replicas: 1
417441
service:
418442
externalTrafficPolicy: Local

‎deploy/experimental-nginx-plus/deploy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -416,11 +418,33 @@ metadata:
416418
spec:
417419
kubernetes:
418420
deployment:
421+
autoscaling:
422+
behavior:
423+
scaleDown:
424+
policies:
425+
- periodSeconds: 180
426+
type: Pods
427+
value: 1
428+
stabilizationWindowSeconds: 300
429+
scaleUp:
430+
policies:
431+
- periodSeconds: 60
432+
type: Pods
433+
value: 2
434+
stabilizationWindowSeconds: 300
435+
enabled: true
436+
maxReplicas: 11
437+
minReplicas: 1
438+
targetCPUUtilizationPercentage: 50
439+
targetMemoryUtilizationPercentage: 50
419440
container:
420441
image:
421442
pullPolicy: Always
422443
repository: private-registry.nginx.com/nginx-gateway-fabric/nginx-plus
423444
tag: edge
445+
resources: {}
446+
pod:
447+
tolerations: []
424448
replicas: 1
425449
service:
426450
externalTrafficPolicy: Local

‎deploy/experimental/deploy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -413,11 +415,33 @@ metadata:
413415
spec:
414416
kubernetes:
415417
deployment:
418+
autoscaling:
419+
behavior:
420+
scaleDown:
421+
policies:
422+
- periodSeconds: 180
423+
type: Pods
424+
value: 1
425+
stabilizationWindowSeconds: 300
426+
scaleUp:
427+
policies:
428+
- periodSeconds: 60
429+
type: Pods
430+
value: 2
431+
stabilizationWindowSeconds: 300
432+
enabled: true
433+
maxReplicas: 11
434+
minReplicas: 1
435+
targetCPUUtilizationPercentage: 50
436+
targetMemoryUtilizationPercentage: 50
416437
container:
417438
image:
418439
pullPolicy: Always
419440
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
420441
tag: edge
442+
resources: {}
443+
pod:
444+
tolerations: []
421445
replicas: 1
422446
service:
423447
externalTrafficPolicy: Local

‎deploy/nginx-plus/deploy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -411,11 +413,33 @@ metadata:
411413
spec:
412414
kubernetes:
413415
deployment:
416+
autoscaling:
417+
behavior:
418+
scaleDown:
419+
policies:
420+
- periodSeconds: 180
421+
type: Pods
422+
value: 1
423+
stabilizationWindowSeconds: 300
424+
scaleUp:
425+
policies:
426+
- periodSeconds: 60
427+
type: Pods
428+
value: 2
429+
stabilizationWindowSeconds: 300
430+
enabled: true
431+
maxReplicas: 11
432+
minReplicas: 1
433+
targetCPUUtilizationPercentage: 50
434+
targetMemoryUtilizationPercentage: 50
414435
container:
415436
image:
416437
pullPolicy: Always
417438
repository: private-registry.nginx.com/nginx-gateway-fabric/nginx-plus
418439
tag: edge
440+
resources: {}
441+
pod:
442+
tolerations: []
419443
replicas: 1
420444
service:
421445
externalTrafficPolicy: Local

‎deploy/nodeport/deploy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -408,11 +410,33 @@ metadata:
408410
spec:
409411
kubernetes:
410412
deployment:
413+
autoscaling:
414+
behavior:
415+
scaleDown:
416+
policies:
417+
- periodSeconds: 180
418+
type: Pods
419+
value: 1
420+
stabilizationWindowSeconds: 300
421+
scaleUp:
422+
policies:
423+
- periodSeconds: 60
424+
type: Pods
425+
value: 2
426+
stabilizationWindowSeconds: 300
427+
enabled: true
428+
maxReplicas: 11
429+
minReplicas: 1
430+
targetCPUUtilizationPercentage: 50
431+
targetMemoryUtilizationPercentage: 50
411432
container:
412433
image:
413434
pullPolicy: Always
414435
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
415436
tag: edge
437+
resources: {}
438+
pod:
439+
tolerations: []
416440
replicas: 1
417441
service:
418442
externalTrafficPolicy: Local

‎deploy/openshift/deploy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -430,11 +432,33 @@ metadata:
430432
spec:
431433
kubernetes:
432434
deployment:
435+
autoscaling:
436+
behavior:
437+
scaleDown:
438+
policies:
439+
- periodSeconds: 180
440+
type: Pods
441+
value: 1
442+
stabilizationWindowSeconds: 300
443+
scaleUp:
444+
policies:
445+
- periodSeconds: 60
446+
type: Pods
447+
value: 2
448+
stabilizationWindowSeconds: 300
449+
enabled: true
450+
maxReplicas: 11
451+
minReplicas: 1
452+
targetCPUUtilizationPercentage: 50
453+
targetMemoryUtilizationPercentage: 50
433454
container:
434455
image:
435456
pullPolicy: Always
436457
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
437458
tag: edge
459+
resources: {}
460+
pod:
461+
tolerations: []
438462
replicas: 1
439463
service:
440464
externalTrafficPolicy: Local

‎deploy/snippets-filters-nginx-plus/deploy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -414,11 +416,33 @@ metadata:
414416
spec:
415417
kubernetes:
416418
deployment:
419+
autoscaling:
420+
behavior:
421+
scaleDown:
422+
policies:
423+
- periodSeconds: 180
424+
type: Pods
425+
value: 1
426+
stabilizationWindowSeconds: 300
427+
scaleUp:
428+
policies:
429+
- periodSeconds: 60
430+
type: Pods
431+
value: 2
432+
stabilizationWindowSeconds: 300
433+
enabled: true
434+
maxReplicas: 11
435+
minReplicas: 1
436+
targetCPUUtilizationPercentage: 50
437+
targetMemoryUtilizationPercentage: 50
417438
container:
418439
image:
419440
pullPolicy: Always
420441
repository: private-registry.nginx.com/nginx-gateway-fabric/nginx-plus
421442
tag: edge
443+
resources: {}
444+
pod:
445+
tolerations: []
422446
replicas: 1
423447
service:
424448
externalTrafficPolicy: Local

‎deploy/snippets-filters/deploy.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ rules:
5454
- apiGroups:
5555
- ""
5656
- apps
57+
- autoscaling
5758
resources:
5859
- secrets
5960
- configmaps
6061
- serviceaccounts
6162
- services
6263
- deployments
6364
- daemonsets
65+
- horizontalpodautoscalers
6466
verbs:
6567
- create
6668
- update
@@ -411,11 +413,33 @@ metadata:
411413
spec:
412414
kubernetes:
413415
deployment:
416+
autoscaling:
417+
behavior:
418+
scaleDown:
419+
policies:
420+
- periodSeconds: 180
421+
type: Pods
422+
value: 1
423+
stabilizationWindowSeconds: 300
424+
scaleUp:
425+
policies:
426+
- periodSeconds: 60
427+
type: Pods
428+
value: 2
429+
stabilizationWindowSeconds: 300
430+
enabled: true
431+
maxReplicas: 11
432+
minReplicas: 1
433+
targetCPUUtilizationPercentage: 50
434+
targetMemoryUtilizationPercentage: 50
414435
container:
415436
image:
416437
pullPolicy: Always
417438
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
418439
tag: edge
440+
resources: {}
441+
pod:
442+
tolerations: []
419443
replicas: 1
420444
service:
421445
externalTrafficPolicy: Local

‎internal/controller/manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"google.golang.org/grpc"
1313
appsv1 "k8s.io/api/apps/v1"
1414
authv1 "k8s.io/api/authentication/v1"
15+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1516
apiv1 "k8s.io/api/core/v1"
1617
discoveryV1 "k8s.io/api/discovery/v1"
1718
rbacv1 "k8s.io/api/rbac/v1"
@@ -91,6 +92,7 @@ func init() {
9192
utilruntime.Must(ngfAPIv1alpha2.AddToScheme(scheme))
9293
utilruntime.Must(apiext.AddToScheme(scheme))
9394
utilruntime.Must(appsv1.AddToScheme(scheme))
95+
utilruntime.Must(autoscalingv2.AddToScheme(scheme))
9496
utilruntime.Must(authv1.AddToScheme(scheme))
9597
utilruntime.Must(rbacv1.AddToScheme(scheme))
9698
}

‎internal/controller/provisioner/handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/go-logr/logr"
1111
appsv1 "k8s.io/api/apps/v1"
12+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1213
corev1 "k8s.io/api/core/v1"
1314
rbacv1 "k8s.io/api/rbac/v1"
1415
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -62,7 +63,7 @@ func (h *eventHandler) HandleEventBatch(ctx context.Context, logger logr.Logger,
6263
case *gatewayv1.Gateway:
6364
h.store.updateGateway(obj)
6465
case *appsv1.Deployment, *appsv1.DaemonSet, *corev1.ServiceAccount,
65-
*corev1.ConfigMap, *rbacv1.Role, *rbacv1.RoleBinding:
66+
*corev1.ConfigMap, *rbacv1.Role, *rbacv1.RoleBinding, *autoscalingv2.HorizontalPodAutoscaler:
6667
objLabels := labels.Set(obj.GetLabels())
6768
if h.labelSelector.Matches(objLabels) {
6869
gatewayName := objLabels.Get(controller.GatewayLabel)

‎internal/controller/provisioner/objects.go

Lines changed: 174 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"log"
78
"maps"
89
"sort"
910
"strconv"
1011
"time"
1112

1213
appsv1 "k8s.io/api/apps/v1"
14+
autoscalingv2 "k8s.io/api/autoscaling/v2"
1315
corev1 "k8s.io/api/core/v1"
1416
rbacv1 "k8s.io/api/rbac/v1"
1517
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -152,6 +154,7 @@ func (p *NginxProvisioner) buildNginxResourceObjects(
152154
// role/binding (if openshift)
153155
// service
154156
// deployment/daemonset
157+
// hpa
155158

156159
objects := make([]client.Object, 0, len(configmaps)+len(secrets)+len(openshiftObjs)+3)
157160
objects = append(objects, secrets...)
@@ -160,7 +163,25 @@ func (p *NginxProvisioner) buildNginxResourceObjects(
160163
if p.isOpenshift {
161164
objects = append(objects, openshiftObjs...)
162165
}
163-
objects = append(objects, service, deployment)
166+
167+
if nProxyCfg.Kubernetes.Deployment.Autoscaling.Enabled {
168+
hpaAnnotations := make(map[string]string)
169+
if nProxyCfg.Kubernetes.Deployment.Autoscaling.HPAAnnotations != nil {
170+
for key, value := range nProxyCfg.Kubernetes.Deployment.Autoscaling.HPAAnnotations {
171+
hpaAnnotations[string(key)] = string(value)
172+
}
173+
}
174+
175+
objectMeta.Annotations = hpaAnnotations
176+
177+
hpa := buildNginxDeploymentHPA(
178+
objectMeta,
179+
nProxyCfg,
180+
)
181+
objects = append(objects, service, deployment, hpa)
182+
} else {
183+
objects = append(objects, service, deployment)
184+
}
164185

165186
return objects, err
166187
}
@@ -895,6 +916,153 @@ func (p *NginxProvisioner) buildImage(nProxyCfg *graph.EffectiveNginxProxy) (str
895916
return fmt.Sprintf("%s:%s", image, tag), pullPolicy
896917
}
897918

919+
func getMetricTargetByType(
920+
target autoscalingv2.MetricTarget,
921+
) autoscalingv2.MetricTarget {
922+
923+
switch target.Type {
924+
case autoscalingv2.UtilizationMetricType:
925+
return autoscalingv2.MetricTarget{
926+
Type: autoscalingv2.UtilizationMetricType,
927+
AverageUtilization: target.AverageUtilization,
928+
}
929+
930+
case autoscalingv2.AverageValueMetricType:
931+
return autoscalingv2.MetricTarget{
932+
Type: autoscalingv2.AverageValueMetricType,
933+
AverageValue: target.AverageValue,
934+
}
935+
936+
case autoscalingv2.ValueMetricType:
937+
return autoscalingv2.MetricTarget{
938+
Type: autoscalingv2.ValueMetricType,
939+
Value: target.Value,
940+
}
941+
default:
942+
return autoscalingv2.MetricTarget{}
943+
}
944+
945+
}
946+
947+
func buildNginxDeploymentHPA(
948+
objectMeta metav1.ObjectMeta,
949+
nProxyCfg *graph.EffectiveNginxProxy,
950+
) *autoscalingv2.HorizontalPodAutoscaler {
951+
var metrics []autoscalingv2.MetricSpec
952+
953+
cpuUtil := nProxyCfg.Kubernetes.Deployment.Autoscaling.TargetCPUUtilizationPercentage
954+
memUtil := nProxyCfg.Kubernetes.Deployment.Autoscaling.TargetMemoryUtilizationPercentage
955+
autoscalingTemplate := nProxyCfg.Kubernetes.Deployment.Autoscaling.AutoscalingTemplate
956+
957+
if cpuUtil != nil {
958+
metrics = append(metrics, autoscalingv2.MetricSpec{
959+
Type: autoscalingv2.ResourceMetricSourceType,
960+
Resource: &autoscalingv2.ResourceMetricSource{
961+
Name: "cpu",
962+
Target: autoscalingv2.MetricTarget{
963+
Type: autoscalingv2.UtilizationMetricType,
964+
AverageUtilization: cpuUtil,
965+
},
966+
},
967+
})
968+
}
969+
970+
if memUtil != nil {
971+
metrics = append(metrics, autoscalingv2.MetricSpec{
972+
Type: autoscalingv2.ResourceMetricSourceType,
973+
Resource: &autoscalingv2.ResourceMetricSource{
974+
Name: "memory",
975+
Target: autoscalingv2.MetricTarget{
976+
Type: autoscalingv2.UtilizationMetricType,
977+
AverageUtilization: memUtil,
978+
},
979+
},
980+
})
981+
}
982+
983+
if autoscalingTemplate != nil {
984+
for _, addtionalAutoscaling := range *autoscalingTemplate {
985+
986+
switch addtionalAutoscaling.Type {
987+
case autoscalingv2.ResourceMetricSourceType:
988+
metrics = append(metrics, autoscalingv2.MetricSpec{
989+
Type: addtionalAutoscaling.Type,
990+
Resource: &autoscalingv2.ResourceMetricSource{
991+
Name: addtionalAutoscaling.Resource.Name,
992+
Target: getMetricTargetByType(addtionalAutoscaling.Resource.Target),
993+
},
994+
})
995+
996+
case autoscalingv2.PodsMetricSourceType:
997+
metrics = append(metrics, autoscalingv2.MetricSpec{
998+
Type: addtionalAutoscaling.Type,
999+
Pods: &autoscalingv2.PodsMetricSource{
1000+
Metric: addtionalAutoscaling.Pods.Metric,
1001+
Target: getMetricTargetByType(addtionalAutoscaling.Pods.Target),
1002+
},
1003+
})
1004+
1005+
case autoscalingv2.ContainerResourceMetricSourceType:
1006+
metrics = append(metrics, autoscalingv2.MetricSpec{
1007+
Type: addtionalAutoscaling.Type,
1008+
ContainerResource: &autoscalingv2.ContainerResourceMetricSource{
1009+
Name: addtionalAutoscaling.ContainerResource.Name,
1010+
Target: getMetricTargetByType(addtionalAutoscaling.ContainerResource.Target),
1011+
Container: addtionalAutoscaling.ContainerResource.Container,
1012+
},
1013+
})
1014+
1015+
case autoscalingv2.ObjectMetricSourceType:
1016+
metrics = append(metrics, autoscalingv2.MetricSpec{
1017+
Type: addtionalAutoscaling.Type,
1018+
Object: &autoscalingv2.ObjectMetricSource{
1019+
DescribedObject: addtionalAutoscaling.Object.DescribedObject,
1020+
Target: getMetricTargetByType(addtionalAutoscaling.Object.Target),
1021+
Metric: autoscalingv2.MetricIdentifier{
1022+
Name: addtionalAutoscaling.Object.Metric.Name,
1023+
Selector: addtionalAutoscaling.Object.Metric.Selector,
1024+
},
1025+
},
1026+
})
1027+
1028+
case autoscalingv2.ExternalMetricSourceType:
1029+
metrics = append(metrics, autoscalingv2.MetricSpec{
1030+
Type: addtionalAutoscaling.Type,
1031+
External: &autoscalingv2.ExternalMetricSource{
1032+
Metric: autoscalingv2.MetricIdentifier{
1033+
Name: addtionalAutoscaling.External.Metric.Name,
1034+
Selector: addtionalAutoscaling.External.Metric.Selector,
1035+
},
1036+
Target: getMetricTargetByType(addtionalAutoscaling.External.Target),
1037+
},
1038+
})
1039+
}
1040+
}
1041+
}
1042+
1043+
if len(metrics) == 0 {
1044+
log.Fatal("No HPA metric provided")
1045+
return nil
1046+
}
1047+
1048+
hpa := &autoscalingv2.HorizontalPodAutoscaler{
1049+
ObjectMeta: objectMeta,
1050+
Spec: autoscalingv2.HorizontalPodAutoscalerSpec{
1051+
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
1052+
APIVersion: "apps/v1",
1053+
Kind: "Deployment",
1054+
Name: objectMeta.Name,
1055+
},
1056+
MinReplicas: &nProxyCfg.Kubernetes.Deployment.Autoscaling.MinReplicas,
1057+
MaxReplicas: nProxyCfg.Kubernetes.Deployment.Autoscaling.MaxReplicas,
1058+
Metrics: metrics,
1059+
Behavior: nProxyCfg.Kubernetes.Deployment.Autoscaling.Behavior,
1060+
},
1061+
}
1062+
1063+
return hpa
1064+
}
1065+
8981066
// TODO(sberman): see about how this can be made more elegant. Maybe create some sort of Object factory
8991067
// that can better store/build all the objects we need, to reduce the amount of duplicate object lists that we
9001068
// have everywhere.
@@ -906,6 +1074,7 @@ func (p *NginxProvisioner) buildNginxResourceObjectsForDeletion(deploymentNSName
9061074
// serviceaccount
9071075
// configmaps
9081076
// secrets
1077+
// hpa
9091078

9101079
objectMeta := metav1.ObjectMeta{
9111080
Name: deploymentNSName.Name,
@@ -921,8 +1090,11 @@ func (p *NginxProvisioner) buildNginxResourceObjectsForDeletion(deploymentNSName
9211090
service := &corev1.Service{
9221091
ObjectMeta: objectMeta,
9231092
}
1093+
hpa := &autoscalingv2.HorizontalPodAutoscaler{
1094+
ObjectMeta: objectMeta,
1095+
}
9241096

925-
objects := []client.Object{deployment, daemonSet, service}
1097+
objects := []client.Object{deployment, daemonSet, service, hpa}
9261098

9271099
if p.isOpenshift {
9281100
role := &rbacv1.Role{

‎internal/controller/provisioner/provisioner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func (p *NginxProvisioner) provisionNginx(
200200
var agentConfigMapUpdated, deploymentCreated bool
201201
var deploymentObj *appsv1.Deployment
202202
var daemonSetObj *appsv1.DaemonSet
203+
203204
for _, obj := range objects {
204205
createCtx, cancel := context.WithTimeout(ctx, 30*time.Second)
205206

0 commit comments

Comments
 (0)
Please sign in to comment.