1. Deploy the simple-mongodb helm chart on Rancher

    TypeScript

    To deploy the simple-mongodb Helm chart on a Rancher Kubernetes cluster via Pulumi, you'll use the rancher2 Pulumi provider which allows us to interact with Rancher 2.x resources. First, you should have a Rancher-managed Kubernetes cluster available and access to its Kubeconfig file for Pulumi to interact with.

    Below is a Pulumi TypeScript program that demonstrates how to use the rancher2 provider to deploy a Helm chart to your cluster. Note that this example assumes you already have the Rancher environment set up as Pulumi does not manage the Rancher installation itself.

    1. Initialize a new Pulumi project with pulumi new typescript.
    2. Install the rancher2 provider using npm or yarn: npm install @pulumi/rancher2 or yarn add @pulumi/rancher2.
    3. Replace the contents of index.ts with the below code.

    The program does the following:

    • Establishes a resource representing the Rancher 2.x cluster.
    • Uses the rancher2 module to interact with the specified Rancher cluster by passing it the cluster ID.
    • Deploys the simple-mongodb Helm chart to the cluster.

    Make sure to replace the placeholders with appropriate values, such as simple-mongodb, the version of the chart, the catalog which provides the chart, the clusterId for your Rancher cluster, and other relevant Helm chart values.

    import * as rancher2 from '@pulumi/rancher2'; import * as kubernetes from '@pulumi/kubernetes'; // This is the entry point for the Pulumi program. 'async' is used because // we will be making API calls to Rancher for the cluster information. async function main() { // Define the Rancher cluster that we will be deploying to. // Replace 'your-cluster-id' with the actual ID of your Rancher-managed Kubernetes cluster. const rancherCluster = new rancher2.Cluster('my-rancher-cluster', { clusterId: 'your-cluster-id', }); // Instantiate a Kubernetes provider instance using the kubeconfig from the Rancher cluster. // Make sure this kubeconfig allows you to interact with your cluster with the correct permissions. const k8sProvider = new kubernetes.Provider('my-k8s-provider', { kubeconfig: rancherCluster.kubeConfig, }); // Now, we can deploy the simple-mongodb Helm chart using the Kubernetes provider. // Here we assume 'simple-mongodb' is the name of the Helm chart and should be replaced // with the chart's actual name if different. You may also need to define a specific version // and the name of the catalog that contains the chart. const mongodbHelmChart = new kubernetes.helm.v3.Chart('mongodb-chart', { chart: 'simple-mongodb', // If required, specify the exact version of the chart. Omit if you want to deploy the latest version. version: 'chart-version', // Specify the Helm repository that contains the chart, if it's not a local chart. fetchOpts: { repo: 'https://charts.example.com/', }, // Specify the namespace for deploying the Helm chart. // If the namespace doesn't exist, Helm will create it during the deployment. namespace: 'default', // Define values to override the default chart values. // This part is similar to running 'helm install' with the '--set' option. values: { // Add any value overrides specific to the simple-mongodb chart. // These will depend on the chart's value options. }, }, { provider: k8sProvider }); // Output the status of the deployed Helm chart. // The `.status` can be used to check if the Helm release is deployed successfully. return { releaseStatus: mongodbHelmChart.status, }; } // Call the main function to execute the deployment. main();

    Make sure your Pulumi.yaml has the proper dependencies defined for the @pulumi/rancher2 and @pulumi/kubernetes packages.

    After setting up the above code, you can perform the deployment with the command pulumi up. This command starts the deployment process handled by Pulumi, which will deploy your Helm chart to the Rancher-managed Kubernetes cluster.

    Please replace the placeholders like your-cluster-id, chart-version, and chart values with your specific requirements. Depending on the requirements of the simple-mongodb chart, you might have to provide additional configuration under the values key in the same structure as you would in a regular values.yaml file used in Helm.