1. Deploy the dotnet-app helm chart on Rancher


    To deploy a Helm chart for a dotnet application on Rancher using Pulumi, we first need to install and set up the Rancher 2.x API provider. Then we can use it to launch a Helm chart into a specific Rancher cluster and project.

    Firstly, a brief introduction to the involved resources:

    • Rancher Cluster: Represents a Kubernetes cluster managed by Rancher. It could be imported (already existing) or directly provisioned by Rancher's Kubernetes engine (RKE/RKE2) or any cloud Kubernetes services (EKS, AKS, GKE).

    • Rancher Project: A Rancher concept that allows you to group namespaces and manage access and resources for them. It is similar to a Kubernetes namespace but with additional management features.

    • Helm Chart: A package for Kubernetes applications. Helm charts help define, install, and upgrade even the most complex Kubernetes application.

    Considering that you have a Pulumi project set up, here's how you can create a TypeScript Pulumi program to deploy the dotnet-app Helm chart on Rancher:

    1. Install the required Pulumi packages: Before you begin, you will need to install the Pulumi Rancher 2 provider package. You can do this with npm:

      npm install @pulumi/rancher2
    2. Write the Pulumi program:

    Now, let's begin crafting the TypeScript program. Please ensure that you have valid credentials for Rancher and are authorized to interact with the cluster and project where you'd like to deploy the chart.

    import * as rancher2 from "@pulumi/rancher2"; import * as pulumi from "@pulumi/pulumi"; // Provide the Rancher cluster ID and project ID where the Helm chart will be deployed. const clusterId = "my-rancher-cluster-id"; // Replace with your actual cluster ID. const projectId = "my-rancher-project-id"; // Replace with your actual project ID. // Deploy the dotnet-app Helm chart into the specified Rancher Cluster and Project. const app = new rancher2.AppV2("dotnet-app", { // Specify the cluster and project identifiers here. clusterId: clusterId, projectId: projectId, // Define the repository and chart details. repoName: "my-helm-charts", // Replace with the name of your Helm chart repository. chartName: "dotnet-app", // The name of the chart you want to deploy. chartVersion: "1.0.0", // The version of the chart you want to deploy. // Namespace in the project where the app will be deployed. namespace: "dotnet-namespace", // Replace with the desired namespace. // Values passed into the Helm chart. values: pulumi.output({ // Specify Helm chart values here. // For example: setting image tag and replica count. image: { repository: "my-docker-registry/dotnet-app", tag: "latest", }, replicaCount: 2, }).apply(JSON.stringify), }); // Optional: Export the app name for easy access/reference. export const appName = app.metadata.apply(meta => meta.name);
    1. Explanation of the program:
    • We import both the @pulumi/rancher2 package (which contains the Rancher 2 provider resources) and the @pulumi/pulumi package (the core Pulumi SDK).

    • We define constants for clusterId and projectId, which you will need to replace with the identifiers of the Rancher cluster and project you wish to deploy the Helm chart to.

    • We create a new instance of rancher2.AppV2, which represents the Helm chart deployment in Rancher. This resource allows you to define the necessary details like repository name, chart name, chart version, namespace, and values for the Helm chart.

    • Any configurable parameters within the Helm chart (like image repository, tags, or replica counts) can be set within the values block. These values will be passed to the Helm chart for customization of the deployment. We're converting the values object to a JSON string, as Rancher Apps V2 expect a stringified version of the Helm values.

    • We export the app name using Pulumi's export feature, which can be handy if you need to reference the deployed application elsewhere in your infrastructure or for further commands.

    With this Pulumi program ready, you would typically run pulumi up within your Pulumi project directory to start the deployment process. Pulumi will display a preview of the resources that will be created and, upon confirmation, proceed to instantiate your Helm Chart on Rancher, handling all the details of interfacing with the Rancher API.