From 84e3abf33509efadbb37a4607eb0c18e12113fbe Mon Sep 17 00:00:00 2001 From: Gaurav Abbi Date: Sun, 21 Jan 2024 21:50:56 +0100 Subject: [PATCH] keda-cron-scaler: Add stateful set example --- .gitignore | 6 +++- keda-cron-scaler/README.md | 3 +- keda-cron-scaler/k8s/keda-cron-scaler.yaml | 30 ++++++++++++++-- keda-cron-scaler/k8s/statefulset.yaml | 42 ++++++++++++++++++++++ 4 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 keda-cron-scaler/k8s/statefulset.yaml diff --git a/.gitignore b/.gitignore index 43e3039a..97a04229 100644 --- a/.gitignore +++ b/.gitignore @@ -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 \ No newline at end of file +cap-orders-service/*/chart + +target/ +bin/ +.gradle/ diff --git a/keda-cron-scaler/README.md b/keda-cron-scaler/README.md index ee3d78f4..707fee72 100644 --- a/keda-cron-scaler/README.md +++ b/keda-cron-scaler/README.md @@ -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. diff --git a/keda-cron-scaler/k8s/keda-cron-scaler.yaml b/keda-cron-scaler/k8s/keda-cron-scaler.yaml index daea6268..f490821b 100644 --- a/keda-cron-scaler/k8s/keda-cron-scaler.yaml +++ b/keda-cron-scaler/k8s/keda-cron-scaler.yaml @@ -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 @@ -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 diff --git a/keda-cron-scaler/k8s/statefulset.yaml b/keda-cron-scaler/k8s/statefulset.yaml new file mode 100644 index 00000000..d8a7aec1 --- /dev/null +++ b/keda-cron-scaler/k8s/statefulset.yaml @@ -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