Skip to content

Commit

Permalink
keda-cron-scaler: Add stateful set example
Browse files Browse the repository at this point in the history
  • Loading branch information
abbi-gaurav committed Jan 22, 2024
1 parent 52171b4 commit 84e3abf
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ grpc-python/__pycache__/orders_pb2_grpc.cpython-38.pyc
grpc-python/__pycache__/orders_pb2.cpython-38.pyc
.vscode

cap-orders-service/*/chart
cap-orders-service/*/chart

target/
bin/
.gradle/
3 changes: 2 additions & 1 deletion keda-cron-scaler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ Let's put the cron-based scaler into action and assume we have a **development c
kubectl label namespaces ${NS} istio-injection=enabled
```

3. Create a Function and a Deployment as sample workloads.
3. Create a Function, a Deployment and a StatefulSet as sample workloads.

```shell
kubectl -n ${NS} apply -f k8s/deployment.yaml
kubectl -n ${NS} apply -f k8s/function.yaml
kubectl -n ${NS} apply -f k8s/statefulset.yaml
```

4. Apply KEDA cron-based scaling to these workloads.
Expand Down
30 changes: 28 additions & 2 deletions keda-cron-scaler/k8s/keda-cron-scaler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
- type: cron
metadata:
# The acceptable values would be a value from the IANA Time Zone Database.
timezone: Europe/Berlin
timezone: Europe/Berlin
# At 08:00 AM, Monday through Friday
start: 0 8 * * 1-5
# At 06:00 PM, Monday through Friday
Expand All @@ -42,7 +42,33 @@ spec:
- type: cron
metadata:
# The acceptable values would be a value from the IANA Time Zone Database.
timezone: Europe/Berlin
timezone: Europe/Berlin
# At 08:00 AM, Monday through Friday
start: 0 8 * * 1-5
# At 06:00 PM, Monday through Friday
end: 0 18 * * 1-5
# ie. Your MINIMUM replica count for this workload
desiredReplicas: "1"
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: test-keda-cron-ss-busybox
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: StatefulSet
name: test-keda-cron-ss-busybox
pollingInterval: 10
# immediately scale down the workload
cooldownPeriod: 0
# The workload is ASLEEP by DEFAULT, otherwise, it's Awake.
minReplicaCount: 0
triggers:
- type: cron
metadata:
# The acceptable values would be a value from the IANA Time Zone Database.
timezone: Europe/Berlin
# At 08:00 AM, Monday through Friday
start: 0 8 * * 1-5
# At 06:00 PM, Monday through Friday
Expand Down
42 changes: 42 additions & 0 deletions keda-cron-scaler/k8s/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: test-keda-cron-ss-busybox
name: test-keda-cron-ss-busybox
spec:
serviceName: test-keda-cron-ss-busybox
replicas: 1
selector:
matchLabels:
app: test-keda-cron-ss-busybox
template:
metadata:
labels:
app: test-keda-cron-ss-busybox
spec:
containers:
- image: busybox
name: test-keda-cron-ss-busybox
resources:
requests:
memory: 50Mi
cpu: 20m
limits:
memory: 50Mi
cpu: 20m
volumeMounts:
- name: storage
mountPath: /data
command:
- sleep
- infinity
volumeClaimTemplates:
- metadata:
name: storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi

0 comments on commit 84e3abf

Please sign in to comment.