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

    TypeScript

    To deploy the Knative Helm chart on Google Kubernetes Engine (GKE) using Pulumi, you first need to create a GKE cluster. Once the cluster is up and running, you can then deploy Helm charts to it using Pulumi's support for Helm.

    Below is a Pulumi program in TypeScript that demonstrates how to accomplish this. The program comprises two main parts:

    1. A GKE cluster is created using Pulumi's GCP provider.
    2. The Knative Helm chart is deployed to the GKE cluster using Pulumi's Kubernetes provider.

    I will explain the code as we progress through each step.

    import * as gcp from '@pulumi/gcp'; import * as k8s from '@pulumi/kubernetes'; // Create a GKE cluster. const cluster = new gcp.container.Cluster('knative-gke-cluster', { initialNodeCount: 3, nodeVersion: 'latest', minMasterVersion: 'latest', nodeConfig: { preemptible: true, 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 and Kubeconfig export const clusterName = cluster.name; export const kubeconfig = cluster.endpoint.apply(endpoint => { const context = cluster.name.apply(name => `${gcp.config.project}_${gcp.config.zone}_${name}`); return `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${cluster.masterAuth.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`; }); // Create a Kubernetes Provider instance with the kubeconfig. const provider = new k8s.Provider('gkeK8s', { kubeconfig: kubeconfig, }); // Deploy the Knative Helm chart into our GKE cluster. const knative = new k8s.helm.v3.Release('knative', { chart: 'knative', version: '0.1.0', // replace with actual chart version repositoryOpts: { repo: 'https://knative-charts.storage.googleapis.com' // replace with actual repo if different }, }, { provider }); // Export the Knative status export const knativeStatus = knative.status;

    Explanation

    1. GKE Cluster Creation: We start by importing the necessary Pulumi packages (@pulumi/gcp and @pulumi/kubernetes). We then use @pulumi/gcp to create a new GKE cluster with the specified configuration, including the desired number of nodes, node version, and machine type. The OAuth scopes provided are necessary for the nodes to function correctly with Google Cloud Platform services such as monitoring, logging, and accessing Compute Engine features.

    2. Cluster Exports: After creating the GKE cluster, we export the cluster's name and generate the kubeconfig. This kubeconfig is needed to communicate with the Kubernetes cluster and will be used by the Kubernetes provider.

    3. Kubernetes Provider Instance: We create a new instance of the Kubernetes provider by passing the kubeconfig to it. This provider will interface with our GKE cluster.

    4. Deploying Knative Helm Chart: Finally, we use Pulumi's Helm release resource to deploy the Knative chart to our GKE cluster. Note that here you need to specify the correct chart version and repository URL as appropriate for Knative.

    5. Exports: We export the knativeStatus to see the deployment's status after running the Pulumi program.

    Once you have the code in place, you would run it using the Pulumi CLI tooling. After running pulumi up, Pulumi will provision the GKE cluster and deploy the Knative Helm chart based on this program.