Skip to content

Commit dcd8ad9

Browse files
coolbry95shaun-nx
andauthored
add horizontalpodautoscaler (#3276)
Co-authored-by: Shaun <[email protected]>
1 parent c68a0b0 commit dcd8ad9

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

deployments/helm-chart/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ Parameter | Description | Default
248248
`controller.readyStatus.initialDelaySeconds` | The number of seconds after the Ingress Controller pod has started before readiness probes are initiated. | 0
249249
`controller.enableLatencyMetrics` | Enable collection of latency metrics for upstreams. Requires `prometheus.create`. | false
250250
`controller.minReadySeconds` | Specifies the minimum number of seconds for which a newly created Pod should be ready without any of its containers crashing, for it to be considered available. [docs](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#min-ready-seconds) | 0
251+
`controller.autoscaling.enabled` | Enables HorizontalPodAutoscaling. | false
252+
`controller.autoscaling.annotations` | The annotations of the Ingress Controller HorizontalPodAutoscaler. | {}
253+
`controller.autoscaling.minReplicas` | Minimum number of replicas for the HPA. | 1
254+
`controller.autoscaling.maxReplicas` | Maximum number of replicas for the HPA. | 3
255+
`controller.autoscaling.targetCPUUtilizationPercentage` | The target CPU utilization percentage. | 50
256+
`controller.autoscaling.targetMemoryUtilizationPercentage` | The target memory utilization percentage. | 50
251257
`controller.strategy` | Specifies the strategy used to replace old Pods by new ones. [docs](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy) | {}
252258
`controller.disableIPV6` | Disable IPV6 listeners explicitly for nodes that do not support the IPV6 stack. | false
253259
`rbac.create` | Configures RBAC. | true
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{{- if and .Values.controller.autoscaling.enabled (eq .Values.controller.kind "deployment") (semverCompare ">=1.23.0" .Capabilities.KubeVersion.Version) -}}
2+
apiVersion: autoscaling/v2
3+
kind: HorizontalPodAutoscaler
4+
metadata:
5+
name: {{ include "nginx-ingress.serviceName" . }}
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
{{- include "nginx-ingress.labels" . | nindent 4 }}
9+
{{- if .Values.controller.autoscaling.annotations }}
10+
annotations:
11+
{{ toYaml .Values.controller.autoscaling.annotations | indent 4 }}
12+
{{- end }}
13+
spec:
14+
scaleTargetRef:
15+
apiVersion: apps/v1
16+
kind: Deployment
17+
name: {{ default (include "nginx-ingress.name" .) .Values.controller.name }}
18+
minReplicas: {{ .Values.controller.autoscaling.minReplicas }}
19+
maxReplicas: {{ .Values.controller.autoscaling.maxReplicas }}
20+
metrics:
21+
{{- if .Values.controller.autoscaling.targetCPUUtilizationPercentage }}
22+
- type: Resource
23+
resource:
24+
name: cpu
25+
target:
26+
type: Utilization
27+
averageUtilization: {{ .Values.controller.autoscaling.targetCPUUtilizationPercentage }}
28+
{{- end }}
29+
{{- if .Values.controller.autoscaling.targetMemoryUtilizationPercentage }}
30+
- type: Resource
31+
resource:
32+
name: memory
33+
target:
34+
type: Utilization
35+
averageUtilization: {{ .Values.controller.autoscaling.targetMemoryUtilizationPercentage }}
36+
{{- end }}
37+
{{- end }}

deployments/helm-chart/values.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ controller:
119119
## The termination grace period of the Ingress Controller pod.
120120
terminationGracePeriodSeconds: 30
121121

122+
## HorizontalPodAutoscaling (HPA)
123+
autoscaling:
124+
## Enables HorizontalPodAutoscaling.
125+
enabled: false
126+
## The annotations of the Ingress Controller HorizontalPodAutoscaler.
127+
annotations: {}
128+
## Minimum number of replicas for the HPA.
129+
minReplicas: 1
130+
## Maximum number of replicas for the HPA.
131+
maxReplicas: 3
132+
## The target cpu utilization percentage.
133+
targetCPUUtilizationPercentage: 50
134+
## The target memory utilization percentage.
135+
targetMemoryUtilizationPercentage: 50
136+
122137
## The resources of the Ingress Controller pods.
123138
resources:
124139
requests:

docs/content/installation/installation-with-helm.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ The following tables lists the configurable parameters of the NGINX Ingress Cont
236236
|``controller.readyStatus.initialDelaySeconds`` | The number of seconds after the Ingress Controller pod has started before readiness probes are initiated. | 0 |
237237
|``controller.enableLatencyMetrics`` | Enable collection of latency metrics for upstreams. Requires ``prometheus.create``. | false |
238238
|``controller.minReadySeconds`` | Specifies the minimum number of seconds for which a newly created Pod should be ready, without any of its containers crashing, for it to be considered available. [docs](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#min-ready-seconds) | 0 |
239+
|``controller.autoscaling.enabled`` | Enables HorizontalPodAutoscaling. | false |
240+
|``controller.autoscaling.annotations`` | The annotations of the Ingress Controller HorizontalPodAutoscaler. | {} |
241+
|``controller.autoscaling.minReplicas`` | Minimum number of replicas for the HPA. | 1 |
242+
|``controller.autoscaling.maxReplicas`` | Maximum number of replicas for the HPA. | 3 |
243+
|``controller.autoscaling.targetCPUUtilizationPercentage`` | The target CPU utilization percentage. | 50 |
244+
|``controller.autoscaling.targetMemoryUtilizationPercentage`` | The target memory utilization percentage. | 50 |
239245
|``controller.strategy`` | Specifies the strategy used to replace old Pods with new ones. [docs](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy) | {} |
240246
| `controller.disableIPV6` | Disable IPV6 listeners explicitly for nodes that do not support the IPV6 stack. | false |
241247
|``rbac.create`` | Configures RBAC. | true |

0 commit comments

Comments
 (0)