Skip to content

Commit 322dee8

Browse files
add automatic scaledown
1 parent 2bac9b4 commit 322dee8

File tree

5 files changed

+91
-5
lines changed

5 files changed

+91
-5
lines changed

charts/cf-vcluster/templates/ingresses.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ spec:
1818
- path: /
1919
pathType: {{ $.Values.vcluster.controlPlane.ingress.pathType }}
2020
backend:
21-
{{- if $ingress.backendServiceOverride}}
21+
{{- if $.Values.automaticScaleDown.enabled}}
2222
service:
23-
name: {{ $ingress.backendServiceOverride.name }}
23+
name: {{ $.Release.Name }}-keda-http-interceptor
2424
port:
25-
number: {{ $ingress.backendServiceOverride.port }}
25+
number: {{ $.Values.automaticScaleDown.interceptor.port }}
2626
{{- else }}
2727
service:
2828
name: {{ $.Release.Name }}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{{- if .Values.automaticScaleDown.enabled }}
2+
{{ $vclusterContext := (index .Subcharts "vcluster")}}
3+
apiVersion: http.keda.sh/v1alpha1
4+
kind: HTTPScaledObject
5+
metadata:
6+
name: {{ .Release.Name }}
7+
annotations:
8+
# Workaround for idleReplicaCount - https://github.com/kedacore/http-add-on/pull/594
9+
httpscaledobject.keda.sh/skip-scaledobject-creation: "true"
10+
spec:
11+
hosts:
12+
{{- if .Values.global.ingress.internal.enabled }}
13+
- {{ tpl (printf "%s.%s" .Values.global.ingress.internal.host.name .Values.global.ingress.internal.host.domain) . }}
14+
{{- else if .Values.global.ingress.public.enabled }}
15+
- {{ tpl (printf "%s.%s" .Values.global.ingress.public.host.name .Values.global.ingress.public.host.domain) . }}
16+
{{- else }}
17+
- {{ fail "Cannot enable autoScaledown if no ingress is enabled" }}
18+
{{- end }}
19+
scaleTargetRef:
20+
name: {{ .Release.Name }}
21+
kind: {{ include "vcluster.kind" $vclusterContext }}
22+
apiVersion: apps/v1
23+
service: {{ .Release.Name }}
24+
port: 443
25+
replicas:
26+
min: {{ $vclusterContext.Values.controlPlane.statefulSet.highAvailability.replicas }}
27+
max: {{ $vclusterContext.Values.controlPlane.statefulSet.highAvailability.replicas }}
28+
scaledownPeriod: {{ .Values.automaticScaleDown.periodSeconds }}
29+
scalingMetric:
30+
requestRate:
31+
granularity: 1s
32+
targetValue: 1
33+
window: 1m
34+
---
35+
# Workaround for idleReplicaCount - https://github.com/kedacore/http-add-on/pull/594
36+
apiVersion: keda.sh/v1alpha1
37+
kind: ScaledObject
38+
metadata:
39+
name: {{ .Release.Name }}
40+
spec:
41+
advanced:
42+
restoreToOriginalReplicaCount: true
43+
scalingModifiers: {}
44+
initialCooldownPeriod: {{ .Values.automaticScaleDown.initialCooldownPeriod }}
45+
cooldownPeriod: {{ .Values.automaticScaleDown.periodSeconds }}
46+
maxReplicaCount: {{ $vclusterContext.Values.controlPlane.statefulSet.highAvailability.replicas }}
47+
minReplicaCount: {{ $vclusterContext.Values.controlPlane.statefulSet.highAvailability.replicas }}
48+
idleReplicaCount: 0
49+
pollingInterval: 15
50+
scaleTargetRef:
51+
apiVersion: apps/v1
52+
kind: {{ include "vcluster.kind" $vclusterContext }}
53+
name: {{ .Release.Name }}
54+
triggers:
55+
- metadata:
56+
httpScaledObject: {{ .Release.Name }}
57+
scalerAddress: {{ printf "%s:%d" .Values.automaticScaleDown.httpScaler.host (int64 .Values.automaticScaleDown.httpScaler.port) }}
58+
type: external-push
59+
{{- end }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{- if .Values.automaticScaleDown.enabled }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ .Release.Name }}-keda-http-interceptor
6+
spec:
7+
type: ExternalName
8+
externalName: {{ .Values.automaticScaleDown.interceptor.host}}
9+
{{- end }}

charts/cf-vcluster/values.test.rnd-sandbox.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ global:
66
className: nginx-internal
77
host:
88
domain: rnd-sandbox.cf-infra.com
9+
10+
automaticScaleDown:
11+
enabled: true
12+
periodSeconds: 60

charts/cf-vcluster/values.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ global:
1313
# name: "interceptor-service"
1414
# port: 80
1515
host:
16-
name: "{{ .Release.Name }}"
16+
name: "{{ .Release.Namespace }}-vcluster"
1717
domain: corp.local
1818
public:
1919
enabled: false
@@ -28,7 +28,7 @@ global:
2828
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
2929
nginx.ingress.kubernetes.io/ssl-redirect: "true"
3030
host:
31-
name: "{{ .Release.Name }}"
31+
name: "{{ .Release.Namespace }}-vcluster"
3232
domain: example.com
3333

3434
vcluster:
@@ -138,3 +138,17 @@ vcluster:
138138
rbac:
139139
clusterRole:
140140
enabled: true
141+
142+
# Automatic scaledown with Keda
143+
automaticScaleDown:
144+
enabled: false
145+
# How many seconds to wait until scaler is active from creation (prevent release failure)
146+
initialCooldownPeriod: 120
147+
# -- How many seconds of no requests to vcluster until it is scaled down to zero. Defaults to 12 hours (43200s)
148+
periodSeconds: 43200
149+
interceptor:
150+
host: "keda-add-ons-http-interceptor-proxy.keda"
151+
port: 8443
152+
httpScaler:
153+
host: keda-add-ons-http-external-scaler.keda
154+
port: 9090

0 commit comments

Comments
 (0)