1. Deploy the custom-cron helm chart on Rancher

    TypeScript

    To deploy a custom-cron Helm chart on a Rancher-managed Kubernetes cluster using Pulumi, you will need to:

    1. Install and configure Pulumi with the appropriate provider.
    2. Install and configure the Rancher2 provider for Pulumi.
    3. Use the Pulumi Chart resource to deploy your Helm chart.

    Below is a step-by-step guide and a TypeScript program that demonstrates how to accomplish this.

    Prerequisites

    Make sure you have the following prerequisites installed:

    • Pulumi CLI
    • Access to a Rancher instance and its credentials
    • A Kubernetes cluster managed by Rancher
    • Node.js and npm to run the Pulumi program

    Step 1: Install Pulumi and Rancher2 Providers

    First, you will need to configure Pulumi to use the Rancher2 provider. This provider allows Pulumi to interact with Rancher and deploy resources on a Kubernetes cluster managed by Rancher.

    You can install the Rancher2 provider using npm:

    npm install @pulumi/rancher2

    Step 2: Configure Pulumi with Rancher Credentials

    To provide Pulumi with access to your Rancher instance, you need to set the rancher2 provider's configuration values. These typically include the Rancher API URL, access key, and secret key.

    Step 3: Write the Deployment Code

    Now you are ready to write the Pulumi TypeScript program to deploy your custom-cron Helm chart.

    import * as pulumi from "@pulumi/pulumi"; import * as rancher2 from "@pulumi/rancher2"; import * as kubernetes from "@pulumi/kubernetes"; // Initialize a Pulumi project using the rancher2 provider const provider = new rancher2.Provider("<provider-name>", { apiURL: "<rancher-api-url>", accessToken: "<access-token>", secretKey: "<secret-key>", }); // Reference the cluster to deploy to, using the cluster ID from Rancher const cluster = rancher2.getClusterOutput({ clusterId: "<cluster-id>", }); // Create a new Kubernetes provider which uses the fetched kubeconfig from Rancher const k8sProvider = new kubernetes.Provider("<k8s-provider-name>", { kubeconfig: cluster.kubeConfig, }, { dependsOn: [provider] }); // Deploy the custom-cron helm chart using Pulumi's Chart resource const customCronChart = new kubernetes.helm.v3.Chart("custom-cron-chart", { chart: "custom-cron", // Specify the chart version if necessary version: "<chart-version>", // Add chart values here values: { // Example: use a specific image for the cron job image: "my-custom-cron-image", tag: "latest", }, fetchOpts: { // If your chart is from a custom repository, provide repo details repo: "http://<helm-chart-repo>", }, }, { provider: k8sProvider }); // Optional: Export the chart's status export const chartStatus = customCronChart.status;

    In this program, substitute <provider-name>, <rancher-api-url>, <access-token>, <secret-key>, <cluster-id>, <k8s-provider-name>, <chart-version>, and http://<helm-chart-repo> with your specific values.

    Explanation

    • We import the necessary Pulumi packages for both Rancher2 and Kubernetes.
    • We create a rancher2.Provider to interact with the Rancher API. This is configured with your Rancher API endpoint and credentials.
    • Using rancher2.getClusterOutput, we get the Kubernetes cluster managed by Rancher that we want to deploy to.
    • A kubernetes.Provider is instantiated with the kubeconfig of the Rancher-managed cluster.
    • We define the Helm chart we wish to deploy with kubernetes.helm.v3.Chart. The values property can be used to provide any custom values you want to override in the chart.
    • Optionally, we export the status of the Helm chart as a stack export, which can be used to understand the deployment status.

    Running the Program

    To run this Pulumi program:

    1. Ensure you're in the correct directory where the Pulumi TypeScript file is located.
    2. Initialize a new Pulumi stack with pulumi stack init.
    3. Preview the deployment with pulumi preview to see the changes that will be made.
    4. Deploy the chart with pulumi up.

    After successful deployment, your custom-cron Helm chart will be running on the Rancher-managed Kubernetes cluster.