1. Deploy the preview-apps helm chart on Rancher


    To deploy a Helm chart on Rancher using Pulumi, you would typically use the Pulumi Rancher2 provider. This provider allows you to manage resources in a Rancher environment, and among those resources, there's support to deploy applications using Helm.

    In the following TypeScript program, I'm going to guide you through the steps needed to deploy the "preview-apps" Helm chart on Rancher. The deployment will involve creating a CatalogV2 resource to add the Helm chart repository to Rancher, followed by creating a AppV2 resource that actually deploys the Helm chart to your Rancher cluster.

    To begin with, you need to have the Pulumi CLI installed and configured, as well as access to a Rancher instance where you have permissions to deploy applications.

    Here's how you can write a Pulumi program to deploy the "preview-apps" Helm chart on Rancher:

    import * as rancher2 from "@pulumi/rancher2"; // Cluster information where the Helm chart should be deployed const clusterId = "your-cluster-id"; // Replace with your actual Rancher cluster ID const namespace = "default"; // Replace with your target namespace // Create a new catalog (i.e., Helm chart repository) in Rancher const catalog = new rancher2.CatalogV2("preview-apps-catalog", { clusterId: clusterId, url: "https://charts.your-repo.com", // Replace with the actual Helm repo URL gitRepo: "https://github.com/your-repo/preview-apps", // Replace with the Helm chart's repository gitBranch: "master", }); // Deploy the Helm chart using the AppV2 resource const app = new rancher2.AppV2("preview-apps-deployment", { // Refer to the CatalogV2 resource above repoName: catalog.name, chartName: "preview-apps", // The name of the chart in the repository clusterId: clusterId, namespace: namespace, chartVersion: "0.1.0", // Specify the chart version to deploy // Values to be passed to the Helm chart – this depends on the chart being used values: { // Customize your Helm chart values here // For example, to set image tag and service type, you might do something like: // image: { // tag: "latest", // }, // service: { // type: "ClusterIP", // }, }, }); // Export the app name and the namespace where it is deployed export const appName = app.name; export const appNamespace = app.namespace;

    In this Pulumi program:

    • You're creating a CatalogV2 resource that points Pulumi to your Helm chart's repository. This could be a custom repository or any public repository that hosts the chart.
    • You're creating an AppV2 resource that references the catalog created earlier and specifies the name and version of the Helm chart you want to deploy.
    • The values property in AppV2 is where you would override default chart values with your own. However, you would need to know the specific values supported by your "preview-apps" Helm chart.
    • The export keywords at the end allow you to output the essential information once Pulumi applies this program to your Rancher instance, which you might want to use later or output to the console.

    To run this program:

    • Save the code to a file named index.ts.
    • Run pulumi up in the same directory as the file to see it plan and apply your deployment.
    • If satisfied with the plan, then accept the prompt to deploy the chart to your Rancher cluster.

    Remember to replace placeholders such as your-cluster-id, the Helm repository URL, and any specific values for the Helm chart with actual values from your environment and Helm chart.