1. Deploy the keda-operator helm chart on Kubernetes


    To deploy the keda-operator Helm chart on a Kubernetes cluster using Pulumi, we will make use of the Chart resource from the Pulumi Kubernetes provider. The Chart resource enables us to deploy Helm charts to a Kubernetes cluster. In this case, we will be deploying the KEDA operator, which is a Kubernetes-based event-driven autoscaler.

    To successfully deploy a Helm chart using Pulumi, you must have the following prerequisites:

    • A functional Kubernetes cluster where you have access privileges to deploy resources.
    • Pulumi CLI installed and set up to communicate with your Kubernetes cluster. You can use pulumi login to log in through the CLI to the Pulumi service or use a local login for state storage.
    • Helm must be installed if the chart you are deploying requires Helm client-side operations.

    Here's a Pulumi TypeScript program that demonstrates how to deploy the keda-operator Helm chart to a Kubernetes cluster:

    import * as k8s from "@pulumi/kubernetes"; // Create an instance of the keda-operator Helm chart // Ensure that you specify the correct namespace where you want to deploy KEDA, // and provide any custom values you want to configure. const kedaChart = new k8s.helm.v3.Chart("keda", { namespace: "keda", // Specify the namespace where KEDA should be installed (create it if it doesn't exist) repo: "kedacore", // Helm repository name where KEDA chart is stored chart: "keda", // Chart name version: "2.4.0", // Replace with the desired chart version // You can provide additional configuration values here // For example, if you need to customize the KEDA setup: // values: { // resources: { // limits: { // cpu: "100m", // memory: "128Mi", // }, // requests: { // cpu: "50m", // memory: "64Mi", // }, // }, // watchNamespace: "" // Set to a specific namespace to limit scope or leave empty to watch all namespaces // } }); // Export the KEDA operator deployment name export const kedaOperatorName = kedaChart.getResource("v1/Deployment", "keda/keda-operator").metadata.name;

    Let me walk you through what this program does:

    1. We are importing the Pulumi Kubernetes package which contains the necessary components to interact with Kubernetes.

    2. We create an instance of a Helm chart by invoking new k8s.helm.v3.Chart. The parameters include:

      • "keda": a name we choose for our Pulumi stack resource.
      • An object that contains several properties:
        • namespace: The Kubernetes namespace in which to deploy the KEDA operator. You might need to create this namespace beforehand if it does not already exist.
        • repo: The name of the Helm repository where the KEDA chart is hosted.
        • chart: The name of the Helm chart. In this case, it is simply "keda".
        • version: The version of the chart that you want to install. You should replace "2.4.0" with the current version you wish to deploy.
        • values: This is where you can provide custom configuration for your Helm chart deployment. These values correspond to the values you might typically set in a values.yaml file for Helm. They are optional and can be omitted if the defaults are satisfactory. The example shows how you might set resource limits and requests, but these particular lines are commented out with //.
    3. Finally, we export the deployment name of the KEDA operator so that it can be retrieved easily after the Pulumi program runs. This information might be useful if you need to reference the operator's deployment directly, perhaps in scripts or further Pulumi programs.

    To run the program, you would perform the following steps in your terminal:

    1. pulumi new typescript - to create a new Pulumi project if you have not already done so.
    2. Copy the Pulumi code provided above into the index.ts file in your Pulumi project directory.
    3. Run pulumi up to initiate the deployment process. Pulumi will show you a preview of the resources that will be created and prompt for confirmation before proceeding.

    Upon confirmation, Pulumi will go ahead and deploy the KEDA operator Helm chart to your Kubernetes cluster. You can watch the progress in your terminal, and once the deployment is complete, Pulumi will output the name of the KEDA operator deployment.