1. Using kubernetes keda.sh with bitnami.com

    TypeScript

    Kubernetes Event-driven Autoscaling (KEDA) is an application that allows for event-driven autoscaling of workloads on a Kubernetes cluster. KEDA works by activating and deactivating Kubernetes deployments to scale to and from zero based on events from various sources. The Bitnami catalog offers packaged applications for Kubernetes that can be easily deployed.

    When integrating keda.sh with a Bitnami application, the general steps are:

    1. Deploy the Bitnami application to your Kubernetes cluster.
    2. Install KEDA onto your Kubernetes cluster.
    3. Configure ScaledObjects for the desired scaling behavior, referencing the deployed Bitnami application's deployment.

    Below is a program in TypeScript using Pulumi to deploy a Bitnami Helm Chart (for example, Redis, which is commonly available on Bitnami's catalog) and configure KEDA for scaling the deployed Redis instance based on a sample custom metric.

    import * as k8s from "@pulumi/kubernetes"; // Initialize a Kubernetes Provider const provider = new k8s.Provider("provider", {kubeconfig: process.env.KUBECONFIG}); // Deploy Redis using Bitnami Helm chart const redisChart = new k8s.helm.v3.Chart("redis", { chart: "redis", version: "X.X.X", // Specify the version of the chart here fetchOpts: { repo: "https://charts.bitnami.com/bitnami", }, }, {provider}); // Install the KEDA controller using the KEDA Helm chart. const kedaChart = new k8s.helm.v3.Chart("keda", { chart: "keda", version: "Y.Y.Y", // Specify the version of the KEDA chart here fetchOpts: { repo: "https://kedacore.github.io/charts", }, // The KEDA Helm chart does not require any custom values by default }, {provider}); // Define and install a ScaledObject to scale the Redis deployment based on a custom metric. const redisScaler = new k8s.apiextensions.CustomResource("redis-scaledobject", { apiVersion: "keda.sh/v1alpha1", kind: "ScaledObject", metadata: { name: "redis-scaledobject", namespace: "default", // Use the same namespace as your Redis deployment }, spec: { scaleTargetRef: { name: "redis-master", // This name should match the name of your Redis statefulset or deployment }, pollingInterval: 5, // This is the interval to check each trigger source cooldownPeriod: 30, // This is the period to wait after the last trigger reported active before scaling back to 0 minReplicaCount: 0, // Minimum number of replicas to scale down to maxReplicaCount: 100, // Maximum number of replicas to scale up to triggers: [ // List of triggers, you can configure multiple triggers { type: "redis", // There are various triggers Supported by KEDA, 'redis' is for a Redis workload metadata: { address: "redis-headless.default.svc.cluster.local:6379", // Stack-specific info on how to connect to Redis password: "REDIS_PASSWORD", // The password used to connect to Redis (consider using secretKeyRef for a Kubernetes Secret) listName: "mylist", // The list we're looking at for message counts listLength: "5", // We're triggering if there are 5 or more messages in the list }, }, ], }, }, {provider, dependsOn: [redisChart, kedaChart]}); // Export the Redis host to easily access the Redis instance export const redisHost = redisChart.getResource("v1/Service", "redis-master").metadata.name.apply(svcName => `redis-master.${svcName}.svc.cluster.local`);

    In the provided program:

    • We start by importing the Pulumi Kubernetes library, which allows us to interact with Kubernetes resources in our cluster.

    • We then create a Kubernetes provider instance which allows Pulumi to deploy resources to our specified cluster.

    • The redisChart object deploys the Redis bitnami helm chart, where X.X.X is the version you want to deploy. Make sure to replace this with the correct version number.

    • The kedaChart object deploys KEDA onto your cluster using its Helm chart. Similarly, replace Y.Y.Y with the version of the KEDA Helm chart you're using.

    • A ScaledObject, redisScaler, is defined for KEDA. This object tells KEDA how to scale the Redis deployment. Pulumi creates the ScaledObject using the configuration that references the Redis deployment that we've created. We define a trigger type of redis with a pointer to a listName as an example, but you should replace this with the actual criteria you wish to use for scaling. If your scaling involves sensitive information like a password, consider using a Kubernetes secret instead of a plain text value.

    • Finally, we export the Redis service host as redisHost, which provides a DNS name through which we can access the Redis service.

    Please ensure you have Pulumi installed and configured with your Kubernetes cluster, and you have Helm CLI installed to fetch the required charts. You can then run pulumi up to deploy this configuration to your cluster. The namespaces and service names should correspond to the actual names used within your environment.