Skip to content

Commit 42f02b6

Browse files
authored
add autoscaler for distributors (#189)
* add autoscaler for distributors Signed-off-by: Tom Hayward <[email protected]> * enable autoscaling in the CI It is not expected that the autoscaling will trigger in the CI, but including it will validate the manifest. Signed-off-by: Tom Hayward <[email protected]>
1 parent 3371ca7 commit 42f02b6

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-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 distributors #189
56
* [FEATURE] Add autoscaler for ingesters #182
67
* [ENHANCEMENT] Define namespace in templates #184
78
* [ENHANCEMENT] Use FQDN for memcached addresses #175

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ Kubernetes: `^1.19.0-0`
413413
| distributor.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].podAffinityTerm.topologyKey | string | `"kubernetes.io/hostname"` | |
414414
| distributor.affinity.podAntiAffinity.preferredDuringSchedulingIgnoredDuringExecution[0].weight | int | `100` | |
415415
| distributor.annotations | object | `{}` | |
416+
| distributor.autoscaling.behavior | object | `{}` | Ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior |
417+
| distributor.autoscaling.enabled | bool | `false` | Creates a HorizontalPodAutoscaler for the distributor pods. |
418+
| distributor.autoscaling.maxReplicas | int | `30` | |
419+
| distributor.autoscaling.minReplicas | int | `2` | |
420+
| distributor.autoscaling.targetCPUUtilizationPercentage | int | `80` | |
421+
| distributor.autoscaling.targetMemoryUtilizationPercentage | int | `0` | |
416422
| distributor.containerSecurityContext.enabled | bool | `true` | |
417423
| distributor.containerSecurityContext.readOnlyRootFilesystem | bool | `true` | |
418424
| distributor.env | list | `[]` | |

ci/test-values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,15 @@ config:
5757

5858
ingester:
5959
replicas: 1
60+
autoscaling:
61+
enabled: true
62+
minReplicas: 1
6063
statefulSet:
6164
enabled: true
6265
distributor:
6366
replicas: 1
67+
autoscaling:
68+
enabled: true
69+
minReplicas: 1
6470
nginx:
6571
replicas: 1

templates/distributor/distributor-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.distributor.annotations | nindent 4 }}
1111
spec:
12+
{{- if not .Values.distributor.autoscaling.enabled }}
1213
replicas: {{ .Values.distributor.replicas }}
14+
{{- end }}
1315
selector:
1416
matchLabels:
1517
{{- include "cortex.distributorSelectorLabels" . | nindent 6 }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{- with .Values.distributor.autoscaling -}}
2+
{{- if .enabled }}
3+
apiVersion: autoscaling/v2beta2
4+
kind: HorizontalPodAutoscaler
5+
metadata:
6+
name: {{ include "cortex.distributorFullname" $ }}
7+
namespace: {{ $.Release.Namespace }}
8+
labels:
9+
{{- include "cortex.distributorLabels" $ | nindent 4 }}
10+
spec:
11+
scaleTargetRef:
12+
apiVersion: apps/v1
13+
kind: Deployment
14+
name: {{ include "cortex.distributorFullname" $ }}
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,17 @@ distributor:
422422
topologyKey: 'kubernetes.io/hostname'
423423

424424
annotations: {}
425+
426+
autoscaling:
427+
# -- Creates a HorizontalPodAutoscaler for the distributor pods.
428+
enabled: false
429+
minReplicas: 2
430+
maxReplicas: 30
431+
targetCPUUtilizationPercentage: 80
432+
targetMemoryUtilizationPercentage: 0 # 80
433+
# -- Ref: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior
434+
behavior: {}
435+
425436
persistence:
426437
subPath:
427438

0 commit comments

Comments
 (0)