Skip to content

Commit 61e320d

Browse files
author
Nowjean
committed
HPA for data plane
1 parent f8cb1fa commit 61e320d

File tree

23 files changed

+938
-9
lines changed

23 files changed

+938
-9
lines changed

apis/v1alpha2/nginxproxy_types.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ type DeploymentSpec struct {
388388
// +optional
389389
Replicas *int32 `json:"replicas,omitempty"`
390390

391+
// Horizontal Pod Autoscaling.
392+
//
393+
// +optional
394+
Autoscaling HPASpec `json:"autoscaling"`
395+
391396
// Pod defines Pod-specific fields.
392397
//
393398
// +optional
@@ -412,6 +417,41 @@ type DaemonSetSpec struct {
412417
Container ContainerSpec `json:"container"`
413418
}
414419

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

apis/v1alpha2/zz_generated.deepcopy.go

Lines changed: 26 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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ 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":{"enabled":false,"maxReplicas":11,"minReplicas":1,"targetCPUUtilizationPercentage":50,"targetMemoryUtilizationPercentage":50},"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":{},"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 | `""` |

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

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ 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+
minReplicas: {{ .Values.nginx.autoscaling.minReplicas }}
21+
maxReplicas: {{ .Values.nginx.autoscaling.maxReplicas }}
22+
targetCPUUtilizationPercentage: {{ .Values.nginx.autoscaling.targetCPUUtilizationPercentage }}
23+
targetMemoryUtilizationPercentage: {{ .Values.nginx.autoscaling.targetMemoryUtilizationPercentage }}
1624
{{- if .Values.nginx.pod }}
1725
pod:
1826
{{- toYaml .Values.nginx.pod | nindent 8 }}

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,45 @@
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+
"enabled": {
104+
"default": false,
105+
"description": "Enable or disable Horizontal Pod Autoscaler",
106+
"required": [],
107+
"title": "enabled",
108+
"type": "boolean"
109+
},
110+
"maxReplicas": {
111+
"default": 11,
112+
"required": [],
113+
"title": "maxReplicas",
114+
"type": "integer"
115+
},
116+
"minReplicas": {
117+
"default": 1,
118+
"description": "hpaAnnotations: {}",
119+
"required": [],
120+
"title": "minReplicas",
121+
"type": "integer"
122+
},
123+
"targetCPUUtilizationPercentage": {
124+
"default": 50,
125+
"required": [],
126+
"title": "targetCPUUtilizationPercentage",
127+
"type": "integer"
128+
},
129+
"targetMemoryUtilizationPercentage": {
130+
"default": 50,
131+
"required": [],
132+
"title": "targetMemoryUtilizationPercentage",
133+
"type": "integer"
134+
}
135+
},
136+
"required": [],
137+
"title": "autoscaling",
138+
"type": "object"
139+
},
101140
"config": {
102141
"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.",
103142
"properties": {
@@ -313,6 +352,14 @@
313352
},
314353
"container": {
315354
"description": "The container configuration for the NGINX container. This is applied globally to all Gateways managed by this\ninstance of NGINX Gateway Fabric.",
355+
"properties": {
356+
"resources": {
357+
"description": "The resource requirements of the NGINX container. You should be set this value, If you want to use dataplane Autoscaling(HPA).",
358+
"required": [],
359+
"title": "resources",
360+
"type": "object"
361+
}
362+
},
316363
"required": [],
317364
"title": "container",
318365
"type": "object"

charts/nginx-gateway-fabric/values.yaml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,28 @@ nginx:
228228
# -- The number of replicas of the NGINX Deployment.
229229
replicas: 1
230230

231+
autoscaling:
232+
# Enable or disable Horizontal Pod Autoscaler
233+
enabled: false
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+
231253
image:
232254
# -- The NGINX image to use.
233255
repository: ghcr.io/nginx/nginx-gateway-fabric/nginx
@@ -431,9 +453,12 @@ nginx:
431453

432454
# -- The container configuration for the NGINX container. This is applied globally to all Gateways managed by this
433455
# instance of NGINX Gateway Fabric.
434-
container: {}
435-
# -- The resource requirements of the NGINX container.
436-
# resources: {}
456+
container:
457+
# -- The resource requirements of the NGINX container. You should be set this value, If you want to use dataplane Autoscaling(HPA).
458+
resources: {}
459+
# requests:
460+
# cpu: 1000m
461+
# memory: 1Gi
437462

438463
# -- The lifecycle of the NGINX container.
439464
# lifecycle: {}

0 commit comments

Comments
 (0)