1. Deploy the kubecost helm chart on Google Kubernetes Engine (GKE)

    TypeScript

    Deploying a Helm chart on Google Kubernetes Engine using Pulumi involves a few steps. Here's what we'll do:

    1. Create a Google Kubernetes Engine (GKE) cluster.
    2. Configure kubectl to connect to the new GKE cluster.
    3. Use the Pulumi harness package to deploy the Kubecost Helm chart.

    Below you will find a detailed Pulumi TypeScript program that:

    • Creates a new GKE cluster using gcp.container.Cluster.
    • Configures kubectl to communicate with the cluster.
    • Deploys the Kubecost Helm chart on the GKE cluster using a Kubernetes provider and the harness.service.Helm resource.

    Please ensure you have Pulumi installed and configured with the appropriate GCP credentials.

    import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; import * as helm from "@pulumi/harness"; // Step 1: Create GKE cluster const cluster = new gcp.container.Cluster("gke-cluster", { initialNodeCount: 1, minMasterVersion: "latest", nodeConfig: { machineType: "n1-standard-1", 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; // Step 2: Configure kubectl to connect to the new GKE cluster const kubeconfig = pulumi. all([cluster.name, cluster.endpoint, cluster.masterAuth]). apply(([name, endpoint, auth]) => { const context = `${gcp.config.project}_${gcp.config.zone}_${name}`; return `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${auth.clusterCaCertificate} server: https://${endpoint} name: ${context} contexts: - context: cluster: ${context} user: ${context} name: ${context} current-context: ${context} kind: Config preferences: {} users: - name: ${context} user: auth-provider: config: cmd-args: config config-helper --format=json cmd-path: gcloud expiry-key: '{.credential.token_expiry}' token-key: '{.credential.access_token}' name: gcp `; }); // // Export the kubeconfig export const kubeConfig = pulumi.secret(kubeconfig); // Step 3: Create a Kubernetes provider instance using the generated kubeconfig const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: kubeconfig, }); // Step 4: Deploy the Helm chart for kubecost using the harness package const kubecostChart = new helm.service.Helm("kubecost", { name: "kubecost", appId: "kubecost", // Replace with the appropriate application ID // Add necessary variables below variables: [{ name: "name", type: "string", value: "kubecost", }], // Harness specific configuration }, { provider: k8sProvider }); // Export the status of the Helm deployment export const kubecostStatus = kubecostChart.status;

    This program starts by importing the required Pulumi modules for GCP, Kubernetes, and Helm. It then creates a GKE cluster, sets up kubectl to connect to this cluster, and finally, deploys the Helm chart for Kubecost using the Kubernetes provider. We also export the cluster name and kubeconfig to interact with the cluster from our local machine if needed.

    Please replace appId in the kubecostChart resource with the appropriate application ID from Harness.

    Different Helm charts have different configurable inputs, known as variables for Helm. Ensure that the correct values are populated accordingly under the variables array.

    Remember that the actual deployment of the Helm chart will happen when you run pulumi up, and it will prompt you before making any changes to your cloud resources.