1. Deploy the mogenius-metrics-server helm chart on Rancher


    To deploy a Helm chart on a Rancher-managed Kubernetes cluster with Pulumi, you will typically go through several steps:

    1. Set Up the Rancher Provider: Initialize the Rancher provider to communicate with your Rancher instance.
    2. Deploy the Helm Chart: You will use Pulumi's infrastructure-as-code capabilities to model the deployment of the Helm chart in a declarative manner.

    Below is a typescript program which demonstrates how you can deploy a Helm chart using Pulumi with the rancher2 provider. It assumes that you have set up and configured Rancher in your Kubernetes cluster and have appropriate credentials to interact with Rancher's API.

    We will use the rancher2.CatalogV2 resource to add a new catalog source if necessary. Then, we'll use the helm.v3.Chart resource from the @pulumi/kubernetes package to deploy the helm chart. Please note that the mogenius-metrics-server should be available in the Helm repository added to the Rancher.

    import * as pulumi from "@pulumi/pulumi"; import * as rancher2 from "@pulumi/rancher2"; import * as k8s from "@pulumi/kubernetes"; // Create a new Rancher2 provider instance const rancher2Provider = new rancher2.Provider("rancher-provider", { apiUrl: "https://<RANCHER_HOST>", accessKey: "<RANCHER_ACCESS_KEY>", secretKey: "<RANCHER_SECRET_KEY>", }); // If the Helm chart you need isn't in a catalog already known to Rancher, // you may need to add a catalog source in Rancher where the Helm chart is located. const catalog = new rancher2.CatalogV2("mogenius-catalog", { clusterId: "<CLUSTER_ID>", // Replace this with your target Rancher cluster ID. url: "<HELM_CHART_REPOSITORY>", // The URL of the Helm chart repository. name: "mogenius-catalog", // A name for the catalog in Rancher. }, { provider: rancher2Provider }); // Deploy the mogenius-metrics-server Helm chart using the deployed Rancher2 provider. const metricsServerChart = new k8s.helm.v3.Chart("mogenius-metrics-server", { chart: "metrics-server", // Name of the Helm chart, assumed to be in the catalog. version: "<CHART_VERSION>", // Specify the chart version if necessary. namespace: "kube-system", // Deploy into the 'kube-system' namespace or as appropriate. }, { provider: rancher2Provider }); // Export the name of the chart we've deployed export const chartName = metricsServerChart.metadata.name;

    In the above example:

    • Replace <RANCHER_HOST>, <RANCHER_ACCESS_KEY>, and <RANCHER_SECRET_KEY> with your Rancher API endpoint and credentials.
    • The rancher2.Provider is the Pulumi Provider for Rancher, which allows you to interact with your Rancher instance and deploy resources into it.
    • The rancher2.CatalogV2 resource is responsible for adding a new Helm catalog to your Rancher, which allows you to deploy applications from that catalog. It requires the URL to the catalog and the clusterId of the cluster where you want to install the chart.
    • The k8s.helm.v3.Chart resource is the standard Pulumi resource to deploy Helm charts in a Kubernetes cluster. You specify the chart name and version to install.
    • To properly instantiate the Helm chart under Rancher's scope, we pass the provider: rancher2Provider option to the Chart which lets Pulumi know to use the Rancher2 provider for this action.
    • We export the name of the chart as a Pulumi stack output for easy access.

    Please ensure that the Helm chart mogenius-metrics-server exists in the repository you specify, and replace <HELM_CHART_REPOSITORY> with the correct URL and <CLUSTER_ID> with your target cluster's ID. If you know the version of the chart you wish to deploy, you can replace <CHART_VERSION> with that version number. If you leave it out, Pulumi will use the latest version available in the repository.

    Note that before you run the pulumi up command to apply this program, you must have the Pulumi CLI installed and authenticated with both Pulumi and your cloud provider. Your Kubernetes cluster should also be accessible through kubectl from your machine.

    This program is a starting point. Depending on the mogenius-metrics-server Helm chart's configuration, you might need to supply additional configuration values using the values field in the Chart resource. Check the Helm chart's documentation for what configuration might be necessary.