1. Deploy the newrelic-infrastructure helm chart on Rancher


    To deploy the newrelic-infrastructure helm chart on Rancher using Pulumi, you need to follow several steps. First, you must set up a Pulumi project and install the required Pulumi Rancher2 provider. With Pulumi, you can define infrastructure as code using familiar programming languages.

    Here is a step-by-step explanation of what we're going to do:

    1. Set up a Pulumi project: Create a new Pulumi project where your code will reside.

    2. Install the necessary Pulumi providers: Ensure that you have the Pulumi Rancher2 provider added to your project so you can interact with your Rancher instance.

    3. Define your Kubernetes cluster: This step assumes you have a Kubernetes cluster managed by Rancher. You will need the cluster ID to deploy workloads to it using Pulumi.

    4. Add the Catalog: Before you can deploy a chart, ensure that the chart's repository (Catalog) is added to Rancher.

    5. Deploy the Helm chart: Use Pulumi's Kubernetes provider to deploy the newrelic-infrastructure helm chart to the targeted Rancher-managed cluster.

    Let's start with the program that accomplishes this task:

    import * as pulumi from "@pulumi/pulumi"; import * as rancher2 from "@pulumi/rancher2"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Initialize a Pulumi program with the rancher2 provider. // Replace `rancherUrl`, `apiToken` and `clusterId` with the actual values. const rancherUrl = 'https://your-rancher-server-url'; const apiToken = 'token-xxxxx'; // Use a secret handling mechanism for production const clusterId = 'c-xxxxx'; // Your target cluster id in Rancher const rancherProvider = new rancher2.Provider("rancherProvider", { apiToken: apiToken, apiUrl: rancherUrl, }); // Step 2: Add the helm chart repository (catalog in Rancher) if it's not already present. const catalog = new rancher2.CatalogV2("newrelic-catalog", { clusterId: clusterId, url: "https://helm-charts.newrelic.com", // The New Relic Helm charts repository URL. }, { provider: rancherProvider }); // Step 3: Initialize a Pulumi Kubernetes provider that targets the cluster managed by Rancher. const k8sProvider = new k8s.Provider("k8s", { kubeconfig: pulumi.output(rancher2.getKubeconfigOutput({ clusterId: clusterId, }, { provider: rancherProvider })).kubeconfig, }); // Step 4: Deploy the New Relic Infrastructure helm chart to the cluster. const newRelicChart = new k8s.helm.v3.Chart("newrelic-infrastructure", { chart: "newrelic-infrastructure", version: "2.0.0", // Use the appropriate version. fetchOpts: { repo: "https://helm-charts.newrelic.com/", }, // Values from the Helm chart's values.yaml can be provided here. values: { // For example, assuming you're supposed to provide a licenseKey. // licenseKey: 'your-new-relic-license-key', }, }, { provider: k8sProvider }); // Export the name of the chart as an output. export const chartName = newRelicChart.metadata.name;

    Here's an explanation of the key parts of this program:

    • rancher2.Provider: This is where you configure the connection to your Rancher server. Replace rancherUrl and apiToken with the URL to your Rancher server and a valid API token respectively.

    • rancher2.CatalogV2: Represents a Helm chart repository in Rancher. If the repository for New Relic is not already added in your Rancher setup, this resource will add it.

    • k8s.Provider: This is Pulumi's Kubernetes provider that can operate on a Kubernetes cluster. It uses the kubeconfig retrieved from Rancher, enabling Pulumi to deploy resources to your cluster.

    • k8s.helm.v3.Chart: Deploys a Helm chart into a Kubernetes cluster. In this script, it's used to deploy newrelic-infrastructure from the catalog (repository) we've added.

    When running this code, replace placeholder values with those specific to your environment:

    • your-rancher-server-url: The URL of your Rancher server.
    • token-xxxxx: A Rancher API token for authentication.
    • c-xxxxx: The ID of the Rancher cluster you are targeting.

    Please note to replace the version and values in the newRelicChart with the appropriate versions and configuration values for the newrelic-infrastructure helm chart. The values should match the values.yaml of the newrelic-infrastructure Helm chart.

    In a production environment, secrets such as the API token should not be hardcoded. Instead, use Pulumi's secret handling, which could be configuration values or environment variables.

    Remember to install the necessary Pulumi packages in your project:

    pulumi plugin install resource rancher2 v5.1.1 npm install @pulumi/pulumi @pulumi/rancher2 @pulumi/kubernetes

    Configure your Pulumi stack.

    Run the Pulumi program using Pulumi CLI commands:

    pulumi up

    This command will prompt you to review the changes and proceed with the deployment of the newrelic-infrastructure helm chart onto your Rancher-managed Kubernetes cluster.