1. Deploy the default-chart helm chart on Rancher


    To deploy a Helm chart on Rancher using Pulumi, you need to set up and configure the Pulumi Rancher2 provider. This provider allows you to manage resources in a Rancher environment, including deploying Helm charts to Kubernetes clusters managed by Rancher.

    Here's a step-by-step guide and a corresponding Pulumi program written in TypeScript that illustrates how to deploy a Helm chart using Pulumi:


    To follow along, make sure you have the following prerequisites in place:

    1. Access to a Rancher instance and at least one Kubernetes cluster managed by Rancher.
    2. The default-chart helm chart you wish to deploy is available in a Helm repository or as local chart files.
    3. Pulumi CLI installed on your machine.
    4. Node.js and npm installed on your machine to run the TypeScript Pulumi program.

    Step-by-step Deployment

    1. Set up Pulumi Rancher2 Provider: You need to set up the Rancher2 provider by providing it with access credentials to communicate with your Rancher server. This typically involves providing the Rancher API URL and an access token.

    2. Define the Helm Chart Deployment: Once the provider is set up, you'll define a resource representing the Helm chart you wish to deploy. In Pulumi, you use the Chart class to represent Helm charts. You'll need to specify the chart name, version, and any values to customize the deployment.

    3. Deploy the Helm Chart: Executing the Pulumi program will result in the chart being deployed to your Kubernetes cluster managed by Rancher.

    Below is the Pulumi TypeScript program that deploys a Helm chart to a Kubernetes cluster in Rancher:

    import * as pulumi from "@pulumi/pulumi"; import * as rancher2 from "@pulumi/rancher2"; // Initialize a Pulumi Rancher2 provider instance. // Ensure that you have the appropriate access token and Rancher API URL configured. const provider = new rancher2.Provider("rancher", { apiURL: "https://<Rancher_API_URL>/v3", accessToken: "<ACCESS_TOKEN>", }); // Deploy a Helm chart using the Rancher2 provider. // Replace 'default-chart' with the name of your Helm chart and provide the repository URL. // If this is a local chart, the path argument should point to the local directory instead. const chart = new rancher2.AppV2("default-chart", { // Required parameters: clusterId: "<CLUSTER_ID>", // ID of the Kubernetes cluster managed by Rancher where the chart will be deployed. namespace: "default", // Kubernetes namespace where the chart will be deployed. repoName: "<REPO_NAME>", // Name of the helm repository. chartName: "default-chart", // The name of the Helm chart to deploy. // Optional parameters (uncomment and modify as needed): // chartVersion: "1.0.0", // Version of the Helm chart to deploy. // values: { // Custom values to override the Helm chart's default values. // key: "value", // }, // Specify the Rancher2 provider instance. opts: { provider: provider }, }); // Export the name of the chart deployment. export const chartName = chart.name;

    Replace the placeholders <RANCHER_API_URL>, <ACCESS_TOKEN>, <CLUSTER_ID>, and <REPO_NAME> with your specific Rancher API URL, access token, cluster ID, and repository name. You might also need to adjust the namespace, chartName, and chartVersion to match the Helm chart you are deploying.

    To deploy, run the following commands in your terminal:

    • pulumi up: This will start the deployment process.
    • pulumi stack output chartName: This will output the deployed chart name after the deployment is successful.

    In the Pulumi program, we've used the rancher2.AppV2 class from the Pulumi Rancher2 package, which you can import using npm by running npm install @pulumi/rancher2.

    This TypeScript code sample uses Pulumi to instruct Rancher to deploy the specified Helm chart to a Kubernetes cluster. It initializes a new Rancher provider and then declares a Rancher application resource representing the Helm chart.

    Remember to check the official Pulumi Rancher2 documentation for more detail on the usage and options available for the resources.