Deploy the old-joomla helm chart on Rancher
TypeScriptTo deploy a Helm chart, like the
old-joomla
chart, on Rancher using Pulumi, you need to set up a few prerequisites:- A working Rancher environment.
- The
old-joomla
chart accessible in a Helm chart repository or on your local filesystem. - A Pulumi program that interacts with the Rancher cluster to deploy the Helm chart.
In this explanation, I will guide you through creating a Pulumi program in TypeScript that will deploy the
old-joomla
Helm chart on a Rancher Kubernetes cluster. I'll use therancher2
Pulumi provider, which enables you to interact with Rancher. Specifically, theCatalogV2
resource from therancher2
provider can be used to manage catalog repositories in a Rancher server installation, which you can then use to deploy Helm charts to a Rancher-managed Kubernetes cluster.Before you begin with the Pulumi code, ensure the following:
- You have access to a Rancher v2.x cluster.
- You have configured
kubectl
with access to the Rancher cluster. - You have installed Pulumi and set up your Pulumi account.
- You have the Pulumi CLI installed and configured on your system.
- You have node.js and npm/yarn installed on your system to run TypeScript programs.
Here's the Pulumi program:
import * as rancher2 from "@pulumi/rancher2"; import * as k8s from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Initialize a Rancher provider instance using the credentials and Rancher server URL. // Make sure to replace `rancherServerUrl`, `accessToken`, and `accessSecret` with your // actual Rancher server's URL, token key, and token secret respectively. const rancherProvider = new rancher2.Provider("rancher", { apiUrl: pulumi.config.require("rancherServerUrl"), tokenKey: pulumi.config.requireSecret("accessToken"), tokenSecret: pulumi.config.requireSecret("accessSecret"), }); // Reference an existing Rancher project where you want to deploy your Helm chart. // Replace `rancherProjectName` with the name of your Rancher project. const rancherProject = rancher2.getProject({ name: pulumi.config.require("rancherProjectName"), }, { provider: rancherProvider }); // Create a Catalog for the Helm chart repository containing `old-joomla`. const helmChartRepoCatalog = new rancher2.CatalogV2("helmChartRepo", { clusterId: rancherProject.clusterId, // Specify the Helm chart repository URL that contains the `old-joomla` chart. // Replace this with the actual Helm chart repository URL. url: "https://helm-repo-url.com", name: "old-joomla-repo", namespace: "default", }, { provider: rancherProvider }); // Deploy the `old-joomla` Helm chart using the rancher2.AppV2 resource. const joomlaApp = new rancher2.AppV2("old-joomla", { // The cluster and project IDs should point to the cluster/project you want to deploy in. clusterId: rancherProject.clusterId, namespace: "default", projectId: rancherProject.id, repoName: helmChartRepoCatalog.name, chartName: "old-joomla", chartVersion: "1.0.0", // Replace with the version of the chart you want to deploy. values: "", // Optional: Provide additional configuration values for the Helm chart. }, { provider: rancherProvider, dependsOn: [helmChartRepoCatalog] }); // Export the name of the deployed app export const appName = joomlaApp.name;
Here's the breakdown of the steps we are following:
- We start by defining the
rancherProvider
, configuring it with the API URL of your Rancher server as well as the access token and secret. - We then get data from an existing Rancher project where we wish to deploy our Helm chart using the
rancher2.getProject
function. - Next, we create a
CatalogV2
resource, which represents a Helm chart repository. We specify the repository's URL, the cluster ID, and the namespace. - Finally, we deploy the desired Helm chart (
old-joomla
) to the Rancher project by creating anAppV2
resource, which represents the application deployed using a Helm chart. Here, we configure its properties to refer to the chart we would like to deploy, and we can optionally provide additional configuration values specific to theold-joomla
chart.
Remember to replace placeholder values such as the Rancher server URL, access token, secret, and other resource-specific properties with your actual data.
Lastly, note that the actual Helm chart repository URL needs to be provided where the
old-joomla
chart exists. This program assumes you already haveold-joomla
available in a Helm repository that Rancher can access.To run this program:
- Save the code to a file named
index.ts
. - Run
npm install
to get the needed Pulumi packages. - Configure the required variables (
rancherServerUrl
,accessToken
,accessSecret
, andrancherProjectName
) using Pulumi config command. Example:pulumi config set rancherServerUrl <value> --secret
. - Run
pulumi up
to launch the program and deploy the chart onto your Rancher-managed cluster.