1. Deploy the Knative helm chart on Kubernetes


    To deploy the Knative Helm chart on Kubernetes using Pulumi, first you need to have a Kubernetes cluster running and accessible via kubectl. Assuming you have this in place, we'll write a Pulumi program to deploy the Knative Helm chart to the cluster.

    We will use the kubernetes.helm.v3.Chart class from the @pulumi/kubernetes package. This class allows us to declare a Helm chart as part of our Pulumi infrastructure, specifying the chart name, version, and any custom values we might want to use to configure the chart.

    First, we'll need to import the necessary Pulumi packages into our TypeScript program:

    • @pulumi/pulumi: The core Pulumi package for creating, deploying, and managing infrastructure.
    • @pulumi/kubernetes: Provides classes and helpers for working with Kubernetes resources, including Helm charts.

    Let's dive into the code. Below is a Pulumi TypeScript program that deploys the Knative Helm chart to a Kubernetes cluster:

    import * as pulumi from '@pulumi/pulumi'; import * as k8s from '@pulumi/kubernetes'; // Create a new Helm chart deployment for Knative. const knativeChart = new k8s.helm.v3.Chart('knative', { // Specify the Helm chart repository and chart name. // Make sure the version specified is the one you want to install. chart: 'knative', version: '0.1.0', // Replace with the actual chart version you intend to deploy. fetchOpts: { // You must specify the repository where the Knative chart is located. repo: 'https://knative.dev/docs/install', // Replace with the actual Helm repository URL. }, // If your cluster requires additional configuration, such as specifying a namespace, // change the `namespace` property accordingly. namespace: 'knative-serving', // If the chart needs any custom values or if you want to override default values, // you can add them in the `values` object. values: { // Custom values for the Knative installation. // These values will vary depending on the specifics of the Helm chart and your requirements. // Please refer to the Knative Helm chart documentation to understand which values can be set. // Example: // serving: { // enabled: true, // }, // eventing: { // enabled: true, // }, }, }, { provider: /* If you are working with a specific k8s provider, provide it here. */ }); // Export the base URL for the deployed Knative services // This assumes that Knative is configured to expose services externally. export const knativeBaseUrl = knativeChart.getResourceProperty('v1/Service', 'knative-serving', 'status').apply(status => status.loadBalancer.ingress[0].hostname || status.loadBalancer.ingress[0].ip);

    Before running the above code, you'll need to:

    1. Make sure you have Pulumi and Node.js installed on your machine.
    2. Set up your Kubernetes cluster kubeconfig so that Pulumi can access it.
    3. Replace '0.1.0' with the actual version number of the Knative Helm chart that you wish to install.
    4. Replace 'https://knative.dev/docs/install' with the actual Helm repository URL that contains the Knative chart.

    You can install the necessary Pulumi libraries using npm:

    npm install @pulumi/pulumi @pulumi/kubernetes

    After installing the dependencies and configuring your program, you can deploy your Helm chart with Pulumi using the following commands:

    pulumi up

    It will present a preview of the resources to be created and prompt for confirmation before proceeding with the actual deployment.

    The above program will create the Knative services in your Kubernetes cluster. The export line at the end provides a way for you to get the base URL at which your Knative services will be accessible, assuming Knative is configured to expose services externally.

    Please note, the details of custom values for the Knative Helm chart and repository URL are provided as placeholders here. You need to refer to the Knative Helm chart documentation and your environment specifics to use the correct data.