Skip to content

Commit

Permalink
[stable] [nignx-ingress] Add HPA to defaultBackend. Update doc, bump …
Browse files Browse the repository at this point in the history
…version. (helm#23275)

Signed-off-by: Adam Hamsik <adam.hamsik@lablabs.io>
  • Loading branch information
haad authored Jul 22, 2020
1 parent d28702c commit 9954896
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stable/nginx-ingress/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v1
name: nginx-ingress
version: 1.41.1
version: 1.41.2
appVersion: v0.34.1
home: https://github.com/kubernetes/ingress-nginx
description: An nginx Ingress controller that uses ConfigMap to store the nginx configuration.
Expand Down
48 changes: 48 additions & 0 deletions stable/nginx-ingress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ Parameter | Description | Default
`defaultBackend.extraArgs` | Additional default backend container arguments | `{}`
`defaultBackend.extraEnvs` | any additional environment variables to set in the defaultBackend pods | `[]`
`defaultBackend.port` | Http port number | `8080`
`defaultBackend.autoscaling.enabled` | If true, creates Horizontal Pod Autoscaler | false
`defaultBackend.autoscaling.minReplicas` | If autoscaling enabled, this field sets minimum replica count | `1`
`defaultBackend.autoscaling.maxReplicas` | If autoscaling enabled, this field sets maximum replica count | `2`
`defaultBackend.autoscaling.targetCPUUtilizationPercentage` | Target CPU utilization percentage to scale | "50"
`defaultBackend.autoscaling.targetMemoryUtilizationPercentage` | Target memory utilization percentage to scale | "50"
`defaultBackend.livenessProbe.initialDelaySeconds` | Delay before liveness probe is initiated | 30
`defaultBackend.livenessProbe.periodSeconds` | How often to perform the probe | 10
`defaultBackend.livenessProbe.timeoutSeconds` | When the probe times out | 5
Expand Down Expand Up @@ -411,3 +416,46 @@ Error: UPGRADE FAILED: Service "?????-controller" is invalid: spec.clusterIP: In
Detail of how and why are in [this issue](https://github.com/helm/charts/pull/13646) but to resolve this you can set `xxxx.service.omitClusterIP` to `true` where `xxxx` is the service referenced in the error.

As of version `1.26.0` of this chart, by simply not providing any clusterIP value, `invalid: spec.clusterIP: Invalid value: "": field is immutable` will no longer occur since `clusterIP: ""` will not be rendered.

## Using custom default backend

Default can be used to server custom error pages when service endpoints are not available. This is requires custom webserver image build with simmilar configuration as below.

```
server {
listen 80 default_server;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow all;
deny all;
}
location /healthz {
stub_status on;
access_log off;
allow 127.0.0.1;
allow all;
deny all;
}
}
###
# DefaultBackend application handler block
server {
listen 80;
server_name *.example-app.com example-app.com;
access_log /var/log/nginx/access.log main;
root /usr/share/nginx/html;
location / {
add_header Content-Type application/json;
add_header Cache-Control "no-cache, no-store" always;
try_files /maintenance.json =502;
}
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ spec:
{{- if .Values.defaultBackend.useComponentLabel }}
{{ .Values.defaultBackend.componentLabelKeyOverride | default "app.kubernetes.io/component" }}: default-backend
{{- end }}
{{- if not .Values.defaultBackend.autoscaling.enabled }}
replicas: {{ .Values.defaultBackend.replicaCount }}
{{- end }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
template:
metadata:
Expand Down
32 changes: 32 additions & 0 deletions stable/nginx-ingress/templates/default-backend-hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- if .Values.defaultBackend.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
labels:
app: {{ template "nginx-ingress.name" . }}
chart: {{ template "nginx-ingress.chart" . }}
component: "{{ .Values.defaultBackend.name }}"
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
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 }}
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 7 additions & 0 deletions stable/nginx-ingress/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,13 @@ defaultBackend:
# cpu: 10m
# memory: 20Mi

autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 2
targetCPUUtilizationPercentage: 50
targetMemoryUtilizationPercentage: 50

service:
annotations: {}
## Deprecated, instead simply do not provide a clusterIP value
Expand Down

0 comments on commit 9954896

Please sign in to comment.