Skip to content

Commit 564394d

Browse files
authored
add autoscaler for nginx (#249)
* add autoscaler for nginx Signed-off-by: Kevin Labesse <[email protected]> * typo Signed-off-by: Kevin Labesse <[email protected]>
1 parent 4eb1a48 commit 564394d

File tree

6 files changed

+60
-0
lines changed

6 files changed

+60
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master / unreleased
44

5+
* [FEATURE] Add autoscaler for nginx #249
56
* [BUGFIX] Fix nil pointer evaluation when using `ruler.dictonaries` option #242
67
* [DEPENDENCY] Update Helm release memcached to v5.15.5 #241
78
* [DEPENDENCY] Update Helm release memcached to v5.15.8 #247

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,12 @@ Kubernetes: `^1.19.0-0`
502502
| memcached.&ZeroWidthSpace;resources | object | `{}` | |
503503
| nginx.&ZeroWidthSpace;affinity | object | `{}` | |
504504
| nginx.&ZeroWidthSpace;annotations | object | `{}` | |
505+
| nginx.&ZeroWidthSpace;autoscaling.&ZeroWidthSpace;behavior | object | `{}` | Ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior |
506+
| nginx.&ZeroWidthSpace;autoscaling.&ZeroWidthSpace;enabled | bool | `false` | Creates a HorizontalPodAutoscaler for the nginx pods. |
507+
| nginx.&ZeroWidthSpace;autoscaling.&ZeroWidthSpace;maxReplicas | int | `30` | |
508+
| nginx.&ZeroWidthSpace;autoscaling.&ZeroWidthSpace;minReplicas | int | `2` | |
509+
| nginx.&ZeroWidthSpace;autoscaling.&ZeroWidthSpace;targetCPUUtilizationPercentage | int | `80` | |
510+
| nginx.&ZeroWidthSpace;autoscaling.&ZeroWidthSpace;targetMemoryUtilizationPercentage | int | `0` | |
505511
| nginx.&ZeroWidthSpace;config.&ZeroWidthSpace;auth_orgs | list | `[]` | (optional) List of [auth tenants](https://cortexmetrics.io/docs/guides/auth/) to set in the nginx config |
506512
| nginx.&ZeroWidthSpace;config.&ZeroWidthSpace;basicAuthSecretName | string | `""` | (optional) Name of basic auth secret. In order to use this option, a secret with htpasswd formatted contents at the key ".htpasswd" must exist. For example: apiVersion: v1 kind: Secret metadata: name: my-secret namespace: <same as cortex installation> stringData: .htpasswd: | user1:$apr1$/woC1jnP$KAh0SsVn5qeSMjTtn0E9Q0 user2:$apr1$QdR8fNLT$vbCEEzDj7LyqCMyNpSoBh/ Please note that the use of basic auth will not identify organizations the way X-Scope-OrgID does. Thus, the use of basic auth alone will not prevent one tenant from viewing the metrics of another. To ensure tenants are scoped appropriately, explicitly set the `X-Scope-OrgID` header in the nginx config. Example setHeaders: X-Scope-Org-Id: $remote_user |
507513
| nginx.&ZeroWidthSpace;config.&ZeroWidthSpace;client_max_body_size | string | `"1M"` | |

ci/test-values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ querier:
6969
enabled: true
7070
nginx:
7171
replicas: 1
72+
autoscaling:
73+
enabled: true
7274
config:
7375
httpSnippet: |-
7476
# http snippet

templates/nginx/nginx-dep.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ metadata:
99
annotations:
1010
{{- toYaml .Values.nginx.annotations | nindent 4 }}
1111
spec:
12+
{{- if not .Values.nginx.autoscaling.enabled }}
1213
replicas: {{ .Values.nginx.replicas }}
14+
{{- end }}
1315
selector:
1416
matchLabels:
1517
{{- include "cortex.nginxSelectorLabels" . | nindent 6 }}

templates/nginx/nginx-hpa.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{- with .Values.nginx.autoscaling -}}
2+
{{- if .enabled }}
3+
apiVersion: autoscaling/v2beta2
4+
kind: HorizontalPodAutoscaler
5+
metadata:
6+
name: {{ include "cortex.nginxFullname" $ }}
7+
namespace: {{ $.Release.Namespace }}
8+
labels:
9+
{{- include "cortex.nginxLabels" $ | nindent 4 }}
10+
spec:
11+
scaleTargetRef:
12+
apiVersion: apps/v1
13+
kind: Deployment
14+
name: {{ include "cortex.nginxFullname" $ }}
15+
minReplicas: {{ .minReplicas }}
16+
maxReplicas: {{ .maxReplicas }}
17+
metrics:
18+
{{- with .targetCPUUtilizationPercentage }}
19+
- type: Resource
20+
resource:
21+
name: cpu
22+
target:
23+
type: Utilization
24+
averageUtilization: {{ . }}
25+
{{- end }}
26+
{{- with .targetMemoryUtilizationPercentage }}
27+
- type: Resource
28+
resource:
29+
name: memory
30+
target:
31+
type: Utilization
32+
averageUtilization: {{ . }}
33+
{{- end }}
34+
{{- with .behavior }}
35+
behavior:
36+
{{- toYaml . | nindent 4 }}
37+
{{- end }}
38+
{{- end }}
39+
{{- end }}

values.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,16 @@ nginx:
12951295
extraPorts: []
12961296
env: []
12971297

1298+
autoscaling:
1299+
# -- Creates a HorizontalPodAutoscaler for the nginx pods.
1300+
enabled: false
1301+
minReplicas: 2
1302+
maxReplicas: 30
1303+
targetCPUUtilizationPercentage: 80
1304+
targetMemoryUtilizationPercentage: 0 # 80
1305+
# -- Ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior
1306+
behavior: {}
1307+
12981308
store_gateway:
12991309
replicas: 1
13001310

0 commit comments

Comments
 (0)