1. Deploy the Knative helm chart on Rancher

    TypeScript

    To deploy the Knative helm chart on a Rancher-managed Kubernetes cluster using Pulumi, you'll need to perform a few steps. Here's a detailed walk-through:

    1. Set Up Pulumi with Rancher: Ensure you have the rancher2 provider configured in Pulumi. The rancher2 provider allows you to manage Rancher resources. The provider needs to be configured with the necessary credentials to communicate with your Rancher server.

    2. Create a Kubernetes Cluster: Before deploying the Knative helm chart, you need a Kubernetes cluster managed by Rancher. If you don't already have a cluster, you can use Pulumi to create one.

    3. Deploy Helm Chart: With the rancher2 provider, you can deploy helm charts to your Rancher-managed cluster. Pulumi doesn't directly manage helm charts, but it can instruct Rancher to do so.

    Let's write a Pulumi program in TypeScript to accomplish the above steps:

    import * as pulumi from '@pulumi/pulumi'; import * as rancher2 from '@pulumi/rancher2'; // Step 1: Configure the rancher2 provider // Ensure you have valid credentials for Rancher server access. const provider = new rancher2.Provider('rancher-default', { // The apiURL should point to your Rancher server's endpoint apiURL: 'https://rancher.mydomain.com/v3', // Access Key and Secret Key from Rancher's API & Keys Page accessKey: 'token-xxxxx', secretKey: 'xxxxx', }); // Step 2: Define an existing cluster or create a new one // In this case, let's retrieve an existing cluster's ID managed by Rancher: const cluster = rancher2.getCluster({ name: 'my-cluster-name', // replace with your cluster name }); // Step 3: Deploy Knative helm chart on the cluster const knativeChart = new rancher2.AppV2('knative', { // The cluster id where the chart will be installed clusterId: cluster.then(c => c.id), // The namespace in which the chart should be deployed, change or create as necessary namespace: 'knative-serving', // The name of the chart chartName: 'knative', // The repository which contains the chart repoName: 'https://knative.dev/charts', // Version of the chart to deploy chartVersion: '0.1.0', // replace with the desired version }, { provider }); export const knativeChartName = knativeChart.name;

    Explanation:

    • We start by importing the required Pulumi module and rancher2 provider.
    • We configure the rancher2 provider with the necessary credentials pointing to our Rancher API endpoint and our Rancher access and secret keys. These keys have to be created from the Rancher's API & Keys Page, and you need to replace placeholder values with your valid credentials.
    • With the cluster ID, we initiate an AppV2 resource, which Pulumi uses to interface with Rancher's application deployments. Here, we provide the name of the cluster, the namespace where Knative should be deployed, the name and repository of the Knative helm chart, and the chart version.
    • We then export the name of the Knative chart deployment for easy reference using the Pulumi CLI.

    Remember to replace any placeholder values with the actual values from your Rancher and Kubernetes setup. This script expects that you have an existing cluster managed by your Rancher instance and that you have installed Rancher's CLI and configured your Pulumi CLI with the required access tokens.