1. Deploy the helm-nginx helm chart on Rancher

    TypeScript

    Deploying a Helm chart on a Rancher-managed Kubernetes cluster involves several steps. To do this with Pulumi, you must interact with the Rancher 2.x ecosystem. Pulumi doesn't have a dedicated high-level Rancher Helm Chart resource, but you can use the generic rancher2.AppV2 resource to manage Helm chart deployments within Rancher. First, you need to have a Rancher Kubernetes cluster up and running.

    For deployment, we will:

    1. Set up the Pulumi Rancher2 provider.
    2. Create a Cluster object where the Helm chart will be deployed.
    3. Use the AppV2 class from the rancher2 provider to deploy the helm-nginx chart.

    Below is the Pulumi program in TypeScript that illustrates how you could deploy an Nginx Helm chart on a cluster managed by Rancher:

    import * as pulumi from "@pulumi/pulumi"; import * as rancher2 from "@pulumi/rancher2"; // Note: Ensure that you have the necessary Rancher2 credentials configured in your Pulumi stack // or through environment variables. const clusterName = "my-cluster"; // Getting a reference to an existing Rancher cluster // In a real user scenario, you might be creating a new cluster using the `rancher2.Cluster` class. const cluster = rancher2.Cluster.get("myCluster", clusterName); // Deploy the `helm-nginx` chart using the `AppV2` class const nginxApp = new rancher2.AppV2("nginx-app", { namespace: "default", // Assuming the 'default' namespace, create one if different clusterId: cluster.id, // The ID of the Rancher cluster to deploy to repoName: "bitnami", // Replace with your preferred Helm chart repository name chartName: "nginx", // The name of the chart in the repository chartVersion: "8.0.0", // Use the appropriate chart version values: pulumi.output({}).apply(_ => "image:\n tag: latest"), // The values to configure the Helm chart }); // Export the name of the cluster export const clusterName = cluster.name; // Export the namespace of the app export const appNamespace = nginxApp.namespace; // Export the ID of the app export const appId = nginxApp.id;

    This code snippet does the following:

    • It imports the necessary Pulumi and Rancher2 packages.
    • It retrieves an existing Rancher cluster called my-cluster by assuming it has already been created and is being managed by Rancher.
    • It then creates a new application using the AppV2 resource to deploy the Nginx Helm chart from the Bitnami repository. Replace chartVersion with the version of the Nginx chart you wish to deploy. For the values property, customize the Nginx Helm chart settings using the YAML format in a string (currently set to use the latest Nginx image).
    • In the end, the code exports some resource properties for your reference, like the cluster name, application namespace, and application ID.

    Make sure the Rancher2 provider is configured with the proper credentials before running this program. Typically, you would set these in your environment or through Pulumi configuration secrets. The Nginx chart is deployed to the default namespace, but you can change this if you have a different namespace in mind.

    If you would like to create a new cluster instead or manage other Rancher resources, you can use the other Rancher2 resource types available and adjust your Pulumi program accordingly.