1. Deploy the cron helm chart on Rancher

    TypeScript

    To deploy a cron Helm chart on a Rancher-managed Kubernetes cluster using Pulumi, you'll need to interact with Rancher's API to manage the cluster resources. Unfortunately, as of my knowledge cutoff in April 2023, there isn't a direct Pulumi resource that represents a Helm chart deployment on Rancher. However, you can still use Pulumi to provision a Kubernetes cluster on Rancher and then deploy a Helm chart using Kubernetes resources.

    In this case, I will guide you through the process of setting up a Rancher cluster using Pulumi and deploying a Helm chart on it. The deployment of the Helm chart itself assumes you have Helm installed and can be done via a simple command line after you applied your Pulumi configuration.

    Here's what you'll learn:

    1. How to use Pulumi to create a new Kubernetes cluster via the Rancher2 provider.
    2. How to get the kubeconfig file from the provisioned cluster so that you can interact with it using kubectl or Helm.
    3. How to deploy a Helm chart using the Helm CLI after your cluster is set up.

    First, we create the cluster:

    import * as rancher2 from "@pulumi/rancher2"; // Create a new Rancher2 cluster (This should point to your Rancher instance and use your credentials) const cluster = new rancher2.Cluster("my-cluster", { // Specify the details of your Rancher Kubernetes cluster // Note: Replace the placeholder values with actual values from your Rancher setup name: "my-cluster-name", rkeConfig: { // An example node configuration. Ensure that you have nodes configured with // Docker installed and SSH access configured appropriately for Rancher to use. nodes: [{ address: "<Node IP>", user: "ubuntu", role: ["controlplane", "etcd", "worker"], sshKeyPath: "~/.ssh/id_rsa", }], kubernetesVersion: "v1.20.9-rancher1-1", }, // Enable Rancher monitoring and alerting on the created cluster. enableClusterMonitoring: true, enableClusterAlerting: true, }); // Obtain the kubeconfig file required for interacting with the Kubernetes cluster directly. export const kubeconfig = cluster.kubeConfig;

    Once you run the above Pulumi script and the cluster is created, you should get the kubeconfig output from Pulumi in your console. Save this output to a file; you will use this with kubectl or the Helm CLI to interact with your Kubernetes cluster.

    With the kubeconfig file, you can use Helm to deploy a cron job like so:

    export KUBECONFIG=<path-to-your-kubeconfig-file> helm install my-cron-job stable/cronjob --set schedule="0 * * * *"

    Replace <path-to-your-kubeconfig-file> with the actual path to the kubeconfig file you exported from Pulumi.

    Please note that we used a placeholder cron job in the above Helm command. You'll need to specify your Helm chart repository and chart name as well as any additional values or configurations needed by your chart.

    To summarize:

    • We've configured a new cluster on Rancher with Pulumi.
    • We've obtained the kubeconfig to interact with the new cluster.
    • Lastly, we've shown how to invoke Helm to deploy a scheduled job onto our cluster.

    Make sure Helm and kubectl are installed on your system, and replace example values in both the Pulumi program and Helm command with actual values that match your Rancher and Helm setup.