Skip to content

Commit

Permalink
Fit the sample to the task-template
Browse files Browse the repository at this point in the history
  • Loading branch information
mmitoraj authored and abbi-gaurav committed Jan 3, 2024
1 parent dd3eb8f commit 52171b4
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions keda-cron-scaler/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# SAP BTP, Kyma Runtime: Leveraging KEDA module capabilities for efficient and cost-effective scaling
# SAP BTP, Kyma Runtime: Use KEDA Module Capabilities for Efficient and Cost-Effective Scaling

SAP Business Technology Platform (BTP), Kyma runtime is currently in the process of undergoing a pivotal change as it transitions to a modular architecture. This transformation will provide customers with the advantage of a la carte selection of components or capabilities, thereby reducing unnecessary overhead and complexity. One of the first modules to emerge within this novel framework is KEDA (Kubernetes Event-driven Autoscaling).

## Introduction to KEDA

[KEDA](https://keda.sh/), an open-source initiative that facilitates event-driven autoscaling for Kubernetes workloads, was originally developed by Microsoft and Red Hat. It has since become a sandbox project under the Cloud Native Computing Foundation (CNCF). KEDA focuses on autoscaling applications in response to events sourced from a variety of platforms, including Kafka, RabbitMQ, and cloud-specific services such as Azure Service Bus and Google Pub/Sub.

## The Benefits of KEDA
### The Benefits of KEDA

KEDA ushers in a new era of flexibility and efficiency in autoscaling. It enhances Kubernetes' capacity to support fine-grained autoscaling for event-driven workloads. Leveraging KEDA, you can dynamically scale your deployments from zero to any arbitrary number, contingent on the volume of events they are designed to process.

## Activating the KEDA Module in SAP BTP Kyma Runtime
### Activating the KEDA Module in SAP BTP, Kyma Runtime

You can activate KEDA like any other module by adhering to the official guidelines on how to [enable and disable a module](https://help.sap.com/docs/btp/sap-business-technology-platform/enable-and-disable-kyma-module).

## KEDA's Cron-Based Scaler
### KEDA's Cron-Based Scaler

KEDA offers a broad range of scaling strategies, one of which is the **cron-based scaler**. This scaler allows you to schedule scaling actions according to the time of day, an invaluable feature for managing predictable fluctuations in workload.

As an illustration, the cron-based scaler enables you to:

- **Manage High Traffic and Request Volume Peaks**: With the cron-based scaler, you can program your applications to upscale during peak hours or during high-traffic events, such as Black Friday or New Year sales. The same functionality can be used to schedule your applications to upscale during off-peak hours for batch processing tasks.
- **Manage High Traffic and Request Volume Peaks**: With the cron-based scaler, you can program your applications to upscale during peak hours or high-traffic events, such as Black Friday or New Year sales. The same functionality can be used to schedule your applications to upscale during off-peak hours for batch processing tasks.

![bf](assets/keda-scale-bf.png)

Expand All @@ -32,48 +32,45 @@ As an illustration, the cron-based scaler enables you to:
![off-work](assets/keda-scale-off-work.png)

## Scenario
## Context

Lets put cron based scaler to action.
Let's put the cron-based scaler into action and assume we have a **development cluster** where we want to run customer workloads only during work hours, namely, **Monday - Friday, 8 AM to 6 PM**.

Assume we have a **development cluster** where we want to run customer workloads only during work hours.

Lets say **Monday - Friday, 8 AM to 6 PM**

### Prerequisites
## Prerequisites

- [SAP BTP, Kyma runtime instance](../prerequisites/#kyma)
- [Kubernetes tooling](../prerequisites/#kubernetes)
- [KEDA and Serverless Modules enabled in Kyma](https://help.sap.com/docs/btp/sap-business-technology-platform/enable-and-disable-kyma-module)

### Steps
## Procedure

1. Export your namespace's name as an environment variable.

```shell
export NS={your-namespace}
```
```shell
export NS={your-namespace}
```

2. Create the namespace. If you haven't done so already, enable Istio injection.

```shell
kubectl create ns ${NS}
kubectl label namespaces ${NS} istio-injection=enabled
```shell
kubectl create ns ${NS}
kubectl label namespaces ${NS} istio-injection=enabled
```

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

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

4. Apply KEDA cron-based scaling to these workloads.

```shell
kubectl -n ${NS} apply -f k8s/keda-cron-scaler.yaml
```
```shell
kubectl -n ${NS} apply -f k8s/keda-cron-scaler.yaml
```

### How it works
## How It Works

The KEDA `scaledobject` resource can be configured with a trigger of type `cron`. Within the cron scaler, you can specify that the workloads should only run during working hours.

Expand Down Expand Up @@ -109,7 +106,7 @@ spec:
name: test-keda-cron-function
```
### View the events
## View the Events
Check the events occurring at the start or end time of the trigger. In the following example, you can see KEDA scaling down the replicas:
Expand All @@ -127,9 +124,9 @@ LAST SEEN TYPE REASON OBJECT
7m34s Normal ScalingReplicaSet deployment/test-keda-cron-nginx Scaled down replica set test-keda-cron-nginx-86b78b79df to 0 from 1
```

> Note: Events are only available for one hour after the trigger.
> **Note:** Events are only available for one hour after the trigger.
### First-hand experience
## First-Hand Experience

I applied the KEDA cron scaler to all custom workloads in my Kyma cluster.

Expand All @@ -141,7 +138,7 @@ Additionally, the number of nodes (VMs) was reduced from 4 to 3.

![nodes-off](assets/nodes-off-hours.png)

## References
## Related Links

- <https://medium.com/@CloudifyOps/optimizing-kubernetes-workloads-with-keda-custom-metric-driven-pod-autoscaling-7332e674fdc6>
- <https://doc.kaas.thalesdigital.io/docs/Features/keda>

0 comments on commit 52171b4

Please sign in to comment.