Deploy the elasticsearch-legacy helm chart on Rancher
TypeScriptTo deploy the
elasticsearch-legacy
helm chart on a Rancher-managed Kubernetes cluster, you'll first need to ensure that you have access to a Rancher server and have the necessary permissions to deploy applications. We will use Pulumi to create and manage the deployment, and for this task, you'll use therancher2
package from Pulumi as it provides the needed resources.Here is the general process you'll follow in the Pulumi program:
- Import the necessary Pulumi and
rancher2
packages. - Instantiate a Rancher2 provider to communicate with your Rancher instance.
- Create a Catalog that includes the repository containing the
elasticsearch-legacy
helm chart. - Deploy the helm chart to the target Kubernetes cluster managed by Rancher.
Below is the TypeScript program:
import * as pulumi from "@pulumi/pulumi"; import * as rancher2 from "@pulumi/rancher2"; // Create a new Rancher2 provider instance. // Make sure to configure the provider with the appropriate API URL and access credentials. const provider = new rancher2.Provider("my-rancher", { apiURL: "https://your-rancher-api-url", accessToken: "your-access-token", }); // Add a Catalog to your Rancher server that points to the repo containing the Helm chart. const catalog = new rancher2.CatalogV2("elasticsearch-legacy-catalog", { clusterId: "your-cluster-id", url: "https://helm.elastic.co", // The branch containing the Helm chart. gitBranch: "main", // The name can be any identifier and will be used when referencing this catalog. name: "elasticsearch" }, { provider }); // Deploy the `elasticsearch-legacy` helm chart from the Catalog we've just added. const elasticsearchApp = new rancher2.AppV2("elasticsearch-legacy-app", { // Reference to the cluster where the chart will be installed. clusterId: "your-cluster-id", // Specify the previously created catalog name and the chart name. repoName: "elasticsearch", chartName: "elasticsearch-legacy", // Define the namespace where the chart will be deployed. namespace: "default", // Set the values for the chart deployment. These are specific to the `elasticsearch-legacy` chart. values: ` service: type: ClusterIP clusters: - name: elasticsearch `, // Optionally, specify a version. If omitted, the latest version is used. chartVersion: "7.10.0", }, { provider }); // Export the app namespace and name of the installed chart, if needed. export const elasticsearchNamespace = elasticsearchApp.namespace; export const elasticsearchName = elasticsearchApp.name;
In this program:
rancher2.Provider
initializes a new provider to interact with your Rancher instance. You need to specify your Rancher API endpoint and token.rancher2.CatalogV2
represents a Rancher catalog that contains Helm charts. Here, it's configured to point to the official Elastic Helm repository.rancher2.AppV2
represents an application installed via a Helm chart. Thevalues
property allows you to provide custom configuration for your Elasticsearch cluster.
Please replace the placeholders (
your-rancher-api-url
,your-access-token
,your-cluster-id
, etc.) with your actual Rancher API URL, access token, and cluster ID.After you create these resources with Pulumi and do a
pulumi up
, Pulumi will communicate with the Rancher API to deploy theelasticsearch-legacy
helm chart to your specified Kubernetes cluster. The namespace where the application will be deployed is thedefault
namespace, but you can change this to any namespace you have.Remember to configure your Pulumi provider credentials for Rancher before running this code. You can do this by setting the required configurations using
pulumi config set
for therancher2
package or through environment variables.- Import the necessary Pulumi and