Deploy the keda-operator helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the
keda-operator
Helm chart on Google Kubernetes Engine (GKE) using Pulumi, you should follow these steps:-
Set up a GKE Cluster: First, you'll need to create a GKE cluster. This is the environment where your Kubernetes resources will be hosted.
-
Install KEDA using Helm: After the cluster is set up, you'll use Pulumi's Helm support to install the
keda-operator
chart.
Here is the program in TypeScript that performs these steps:
import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; // Create a GKE cluster. const cluster = new gcp.container.Cluster("gke-cluster", { initialNodeCount: 1, minMasterVersion: "latest", // Alternatively specify your desired GKE version nodeVersion: "latest", nodeConfig: { machineType: "n1-standard-1", // Choose the machine type based on your requirements oauthScopes: [ "https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring", ], }, }); // Export the Cluster name export const clusterName = cluster.name; // Export the Kubeconfig to access the GKE cluster. export const kubeconfig = cluster.name.apply(name => { const cluster = gcp.container.getCluster({ name: name, location: cluster.location, project: cluster.project, }); const context = `${gcp.config.project}_${gcp.config.zone}_${name}`; return `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${cluster.masterAuth[0].clusterCaCertificate} server: https://${cluster.endpoint} name: ${context} contexts: - context: cluster: ${context} user: ${context} name: ${context} current-context: ${context} kind: Config preferences: {} users: - name: ${context} user: auth-provider: config: access-token: ${cluster.masterAuth[0].token} cmd-args: config config-helper --format=json cmd-path: gcloud expiry-key: '{.credential.token_expiry}' token-key: '{.credential.access_token}' name: gcp `; }); // Create a Kubernetes provider that uses our GKE cluster. const k8sProvider = new k8s.Provider("gke-k8s", { kubeconfig: kubeconfig, }); // Install KEDA using the Helm chart. const keda = new k8s.helm.v3.Chart("keda", { chart: "keda", version: "2.4.0", // Specify the version of KEDA you want to install fetchOpts: { repo: "https://kedacore.github.io/charts", }, }, { provider: k8sProvider }); // Export the Helm chart name export const kedaChartName = keda.name;
This program does the following:
- Imports the necessary GCP and Kubernetes libraries.
- Creates a GKE cluster within your default GCP project and zone. You might want to customize the
machineType
,minMasterVersion
,nodeVersion
, and other parameters according to your needs. - Generates a kubeconfig file that allows you to interact with your GKE cluster using
kubectl
. - Sets up a Pulumi Kubernetes provider that specifies the kubeconfig file.
- Installs the KEDA Helm chart from the specified Helm repository (
kedacore/charts
) into your GKE cluster using the Pulumi Kubernetes provider.
To run this Pulumi program:
- Save the code to a file with a
.ts
extension, for example,index.ts
. - Run
pulumi up
in the same directory as yourindex.ts
file. This command will deploy your GKE cluster and the KEDA operator to your GCP account.
Remember to configure your Pulumi GCP credentials before running the program and make sure you have permissions to create and manage GKE clusters and install Helm charts.
-