Deploy the monograph-operator helm chart on Rancher
TypeScriptDeploying a Helm chart on a Rancher-managed Kubernetes cluster involves several steps, including setting up the Rancher client within Pulumi, creating a namespace, adding a catalog if your chart is not in the default catalogs, and finally deploying the Helm chart. The following program demonstrates these steps using TypeScript and the Pulumi Rancher 2 provider.
Before we delve into the code, let's briefly outline the steps this Pulumi program will take:
- Create a new Pulumi project: A new project dedicated to the Rancher deployment should be created so that all resources are logically grouped together.
- Set up the Rancher provider: We will configure the Rancher provider to interact with the Rancher API. Credentials and endpoint details will be needed for this setup.
- Define the namespace: It's best practice to deploy applications within their dedicated Kubernetes namespace. This aids in organization and segmentation.
- Add a catalog (if applicable): If the
monograph-operator
Helm chart is part of a catalog that's not already added to Rancher, we'll add this catalog. This is essentially registering a new source of Helm charts that Rancher can manage. - Deploy the Helm chart: Finally, we'll deploy the
monograph-operator
Helm chart to the cluster managed by Rancher.
Below is the complete Pulumi program that accomplishes these steps:
import * as rancher2 from "@pulumi/rancher2"; import { CatalogV2, AppV2 } from "@pulumi/rancher2"; // Initialize the Rancher provider. const provider = new rancher2.Provider("rancherProvider", { apiURL: "https://rancher.my-domain.com/v3", accessToken: "myAccessToken", // Replace with your Rancher access token secretKey: "mySecretKey", // Replace with your Rancher secret key }); // Create a new namespace for our application const appNamespace = new rancher2.Namespace("app-namespace", { name: "monograph-operator", annotations: { "field.cattle.io/projectId": "my-project-id", // Replace with the project ID within Rancher }, projectId: "my-project-id", // Replace with the project ID within Rancher }, { provider }); // If the Helm chart you want to deploy is not in the default catalogs, // you'll need to add a new catalog where the chart is located. const helmCatalog = new CatalogV2("helm-catalog", { clusterId: "my-cluster-id", // Replace with the cluster ID within Rancher name: "monograph-charts", url: "https://charts.monograph.io", // The URL where your helm chart is located gitRepo: "https://github.com/monograph/charts", // If your catalog is maintained in a Git repository gitBranch: "master", }, { provider }); // Deploy the monograph-operator Helm chart from the added catalog. const monographApp = new AppV2("monograph-operator-app", { name: "monograph-operator", namespace: appNamespace.name, repoName: helmCatalog.name, chartName: "monograph-operator", clusterId: "my-cluster-id", // Replace with the cluster ID within Rancher version: "1.0.0", // Specify the chart version values: `{}`, // YAML values to configure the monograph-operator }, { provider, dependsOn: [appNamespace, helmCatalog] }); // Export the app URL by providing the appropriate service endpoint from the deployed resources. export const monographOperatorUrl = ... // Exported URL to access the monograph-operator after deployment
Please replace the placeholder values such as
myAccessToken
,mySecretKey
,my-project-id
, andmy-cluster-id
with actual values from your Rancher setup.Breaking down what we've done:
- We initialize the Rancher provider with the necessary API endpoint and credentials so that Pulumi can communicate with your Rancher setup.
- Then, we create a namespace resource to provide a dedicated space for our
monograph-operator
. - Next, the
CatalogV2
resource is defined if your Helm chart is hosted outside of Rancher's default catalog locations. This resource registration lets Rancher know where it can pull Helm chart data from. - With the namespace and catalog in place, we use the
AppV2
resource to deploy themonograph-operator
Helm chart to the Kubernetes cluster managed by Rancher.
Finally, on completion, you may want to export the URL or other pertinent information that will allow you to interact with the deployed
monograph-operator
. The actual value for themonographOperatorUrl
export will depend on the service type and any ingresses you configure within your Helm chart values.Before running this Pulumi program, ensure you have installed the necessary Pulumi CLI, set up your Rancher environment, and have the Pulumi Rancher 2 provider installed. Additionally, ensure you have access to Rancher with sufficient permissions to carry out these operations.