1. Deploy the elasticsearch-master helm chart on Rancher


    To deploy the elasticsearch-master Helm chart on Rancher using Pulumi, you'll need to perform several steps:

    1. Set up a Rancher 2 Kubernetes cluster.
    2. Add a chart repository to Rancher.
    3. Deploy the Helm chart to the Rancher cluster.

    In this explanation, we'll assume that you have a running Kubernetes cluster managed by Rancher and that you've installed and configured the Pulumi CLI with access to your cloud provider and Rancher.

    We'll use the rancher2 Pulumi provider, which allows us to interact with Rancher 2.x. First, you'll need to create a new Pulumi project and set up the necessary dependencies. For this example, we're using TypeScript as the programming language.

    Step 1: Set up the Pulumi project and dependencies

    After installing the Pulumi CLI and setting up your project, you need to install the rancher2 provider using npm.

    # Initialize a new Pulumi project pulumi new typescript # Install the Rancher2 provider npm install @pulumi/rancher2

    Step 2: Create the Pulumi script to deploy the chart

    Below is a Pulumi program written in TypeScript. This program performs the following actions:

    • Initializes a new Rancher 2 provider.
    • Adds a Helm chart repository to Rancher (if you have a custom repository; otherwise, it can directly refer to a chart available in a public repository).
    • Deploys the elasticsearch-master Helm chart using the rancher2.App resource.

    Here's the Pulumi program:

    import * as pulumi from "@pulumi/pulumi"; import * as rancher2 from "@pulumi/rancher2"; // Initialize the Rancher2 provider const provider = new rancher2.Provider("rancher2", { apiURL: "https://rancher.example.com/v3/", accessKey: "token-xxxxx", secretKey: "xxxxx", }); // Kubernetes cluster to deploy the chart in const clusterId = "c-xxxxx"; // A namespace where to deploy the chart, adjust as needed const namespace = new rancher2.Namespace("elasticsearch-ns", { clusterId: clusterId, name: "elasticsearch", }, { provider: provider }); // Add a Helm chart repository. This step is optional if the chart is already available in your Rancher setup const chartRepo = new rancher2.CatalogV2("chart-repo", { clusterId: clusterId, url: "https://helm.elastic.co", name: "elastic", gitBranch: "master", // Branch to track, adjust if needed }, { provider: provider }); // Deploy the elasticsearch-master Helm chart const elasticsearchApp = new rancher2.App("elasticsearch-app", { clusterId: clusterId, namespaceId: namespace.name, projectName: "project-xxxxx", // Your Rancher project ID targetNamespace: namespace.name, catalogName: chartRepo.name, chart: "elasticsearch-master", // Name of the chart, ensure it exists in the repository version: "7.9.3", // Specify the version of the chart, adjust as needed values: ` # Custom values for the Helm chart can be provided here as YAML service: type: ClusterIP `, }, { provider: provider, dependsOn: [namespace, chartRepo] }); // Export the endpoint of the elasticsearch master service export const elasticsearchEndpoint = pulumi.interpolate`http://elasticsearch.${namespace.metadata.name}.svc.cluster.local:9200/`;

    This program does the following:

    • Configures the rancher2 provider with the API URL and access keys to your Rancher instance.
    • Creates a namespace in the given Kubernetes cluster where the Elasticsearch service will reside.
    • Adds a new catalog to Rancher pointing to the Helm repository for Elasticsearch. If an official chart is used from Helm stable repository, this step might not be necessary.
    • Deploys the elasticsearch-master Helm chart to the Rancher cluster in the specified namespace.

    Please replace the placeholder values like https://rancher.example.com/v3/, token-xxxxx, xxxxx, project-xxxxx, and 7.9.3 with the actual values from your setup.

    Step 3: Run the Pulumi program

    To apply the Pulumi program, you first have to preview the changes with pulumi up --dry-run and then deploy them with pulumi up.

    Keep in mind that you'll need the appropriate privileges in your Rancher installation to create namespaces and deploy Helm charts. As you grow more comfortable with Pulumi and your needs evolve, you may wish to modularize your code, use loops to manage multiple environments, or separate configuration values into separate files.

    Remember to check the Helm chart values and adjust the values field in the rancher2.App resource to match the configuration that you need for your Elasticsearch deployment.