Skip to content

Commit e8399d9

Browse files
committed
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 }}

0 commit comments

Comments
 (0)