From ab9ba3e970138c39a8b2d2a9fb23f5519a9e2941 Mon Sep 17 00:00:00 2001 From: Adam Hamsik Date: Wed, 4 Nov 2020 14:03:50 +0100 Subject: [PATCH] Add Default backend HPA autoscaling. --- charts/ingress-nginx/CHANGELOG.md | 3 ++ charts/ingress-nginx/Chart.yaml | 8 ++--- .../templates/default-backend-deployment.yaml | 2 ++ .../templates/default-backend-hpa.yaml | 29 +++++++++++++++++++ .../default-backend-poddisruptionbudget.yaml | 2 +- charts/ingress-nginx/values.yaml | 7 +++++ 6 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 charts/ingress-nginx/templates/default-backend-hpa.yaml diff --git a/charts/ingress-nginx/CHANGELOG.md b/charts/ingress-nginx/CHANGELOG.md index 04ebf157c2..8032f5b87c 100644 --- a/charts/ingress-nginx/CHANGELOG.md +++ b/charts/ingress-nginx/CHANGELOG.md @@ -4,6 +4,9 @@ This file documents all notable changes to [ingress-nginx](https://github.com/ku ### Unreleased +### 3.9.0 + +- [X] [#6423](https://github.com/kubernetes/ingress-nginx/pull/6423) Add Default backend HPA autoscaling ### 3.8.0 diff --git a/charts/ingress-nginx/Chart.yaml b/charts/ingress-nginx/Chart.yaml index 1f2a2d58fa..9519bf26d2 100644 --- a/charts/ingress-nginx/Chart.yaml +++ b/charts/ingress-nginx/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: ingress-nginx -version: 3.8.0 +version: 3.9.0 appVersion: 0.41.0 home: https://github.com/kubernetes/ingress-nginx description: Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer @@ -16,8 +16,4 @@ engine: gotpl kubeVersion: ">=1.16.0-0" annotations: artifacthub.io/changes: | - - Update jettech/kube-webhook-certgen image - - Added loadBalancerSourceRanges for internal lbs - - Add securitycontext settings on defaultbackend - - Fix controller service annotations - - Initial helm chart changelog + - Add Default backend HPA autoscaling diff --git a/charts/ingress-nginx/templates/default-backend-deployment.yaml b/charts/ingress-nginx/templates/default-backend-deployment.yaml index 9599c23ac2..0baec8b46a 100644 --- a/charts/ingress-nginx/templates/default-backend-deployment.yaml +++ b/charts/ingress-nginx/templates/default-backend-deployment.yaml @@ -11,7 +11,9 @@ spec: matchLabels: {{- include "ingress-nginx.selectorLabels" . | nindent 6 }} app.kubernetes.io/component: default-backend +{{- if not .Values.defaultBackend.autoscaling.enabled }} replicas: {{ .Values.defaultBackend.replicaCount }} +{{- end }} revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} template: metadata: diff --git a/charts/ingress-nginx/templates/default-backend-hpa.yaml b/charts/ingress-nginx/templates/default-backend-hpa.yaml new file mode 100644 index 0000000000..7f345ce9cd --- /dev/null +++ b/charts/ingress-nginx/templates/default-backend-hpa.yaml @@ -0,0 +1,29 @@ +{{- if .Values.defaultBackend.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + labels: + {{- include "ingress-nginx.labels" . | nindent 4 }} + app.kubernetes.io/component: default-backend + name: {{ template "nginx-ingress.defaultBackend.fullname" . }} +spec: + scaleTargetRef: + apiVersion: {{ template "deployment.apiVersion" . }} + kind: Deployment + name: {{ template "nginx-ingress.defaultBackend.fullname" . }} + minReplicas: {{ .Values.defaultBackend.autoscaling.minReplicas }} + maxReplicas: {{ .Values.defaultBackend.autoscaling.maxReplicas }} + metrics: +{{- with .Values.defaultBackend.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ . }} +{{- end }} +{{- with .Values.defaultBackend.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ . }} +{{- end }} +{{- end }} diff --git a/charts/ingress-nginx/templates/default-backend-poddisruptionbudget.yaml b/charts/ingress-nginx/templates/default-backend-poddisruptionbudget.yaml index b6c9c4499a..327d809b95 100644 --- a/charts/ingress-nginx/templates/default-backend-poddisruptionbudget.yaml +++ b/charts/ingress-nginx/templates/default-backend-poddisruptionbudget.yaml @@ -1,4 +1,4 @@ -{{- if gt (.Values.defaultBackend.replicaCount | int) 1 -}} +{{- if or (gt (.Values.defaultBackend.replicaCount | int) 1) (gt (.Values.defaultBackend.autoscaling.minReplicas | int) 1) }} apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: diff --git a/charts/ingress-nginx/values.yaml b/charts/ingress-nginx/values.yaml index 1f3e5783f5..b1b5b4fd11 100644 --- a/charts/ingress-nginx/values.yaml +++ b/charts/ingress-nginx/values.yaml @@ -627,6 +627,13 @@ defaultBackend: # cpu: 10m # memory: 20Mi + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 2 + targetCPUUtilizationPercentage: 50 + targetMemoryUtilizationPercentage: 50 + service: annotations: {}