Deploy the heartbeat helm chart on Rancher
TypeScriptTo deploy the Heartbeat Helm chart on a Rancher-managed Kubernetes cluster, you'll need to use the Rancher 2 Pulumi provider. This provider allows you to interact programmatically with Rancher resources, which includes the ability to install Helm charts on Kubernetes clusters managed by Rancher.
Here's a step-by-step guide, which includes a Pulumi program in TypeScript, that covers the deployment of the Heartbeat Helm chart using Rancher:
-
Setup Pulumi: Before you start, ensure you have Pulumi CLI installed and configured with the necessary cloud credentials. You'll also need access to a Rancher server and credentials for it.
-
Install Node.js and NPM: Pulumi's Node.js SDK uses NPM to manage dependencies, so be sure you have both Node.js and NPM installed.
-
Initialize a New Pulumi project: Run
pulumi new typescript
to create a new Pulumi project and choose "typescript" as the template. -
Install Rancher2 Provider: In your new Pulumi project, install the
@pulumi/rancher2
package, which contains the necessary resources for interacting with Rancher. -
Write the Pulumi Program: Create a Pulumi Stack that will deploy the Heartbeat Helm chart to your Rancher-managed Kubernetes cluster. You'll need to have information such as the Rancher API URL, access key, secret key, and your cluster's ID.
Here is the program that guides you through the process:
import * as rancher2 from "@pulumi/rancher2"; import * as k8s from "@pulumi/kubernetes"; // Provide the configuration for the Rancher provider const config = new pulumi.Config(); const rancherApiUrl = config.require("rancherApiUrl"); const rancherAccessKey = config.requireSecret("rancherAccessKey"); const rancherSecretKey = config.requireSecret("rancherSecretKey"); const clusterId = config.require("clusterId"); // Initialize the Rancher2 provider const rancherProvider = new rancher2.Provider("rancherProvider", { apiUrl: rancherApiUrl, accessKey: rancherAccessKey, secretKey: rancherSecretKey, }); // Fetch the cluster token from Rancher. This is needed to interact with the Kubernetes API of a managed cluster. const clusterToken = rancher2.getClusterAuthToken({ clusterId: clusterId, }, { provider: rancherProvider }); // Initialize the Kubernetes provider to connect to the Rancher-managed cluster const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: clusterToken.kubeConfig, }); // Deploy the Heartbeat Helm chart const heartbeatChart = new k8s.helm.v3.Chart("heartbeatChart", { chart: "heartbeat", version: "7.6.0", // specify the chart version you wish to deploy namespace: "monitoring", // specify the namespace where you want to deploy the chart fetchOpts:{ repo: "https://helm.elastic.co", // the repository where the Helm chart is hosted }, // Specify any values you want to override from the chart's default values values: { // Heartbeat configuration options }, }, { provider: k8sProvider }); // Export the necessary details export const heartbeatChartName = heartbeatChart.metadata.name; export const heartbeatChartNamespace = heartbeatChart.metadata.namespace;
To run this Pulumi program:
- Replace the placeholder values for
rancherApiUrl
,rancherAccessKey
,rancherSecretKey
, andclusterId
with your actual Rancher installation details and your desired configuration. - Run
npm install
to install the dependencies. - Use
pulumi up
to deploy your stack.
The above program does the following:
- Sets up the Rancher provider with your supplied Rancher API endpoint and credentials. Make sure not to hard-code secrets in the actual code; use Pulumi config instead for a secure practice.
- Obtains the Kubeconfig from Rancher for the specified cluster, which allows Pulumi to interact with your Kubernetes cluster managed by Rancher.
- Instantiates the Kubernetes provider with the obtained Kubeconfig to connect to the Kubernetes cluster.
- Uses the Helm chart resource provided by Pulumi to deploy the "heartbeat" chart from the specified Helm repository into the "monitoring" namespace of the Kubernetes cluster.
Remember to replace the version with the actual version of the Heartbeat Helm chart you wish to deploy and fill in the values configuration with settings suitable for your environment.
-