Deploy the mysql-am helm chart on Rancher
TypeScriptTo deploy the
mysql-am
Helm chart on Rancher using Pulumi, we have to go through a number of steps. First, we would need to set up the Rancher provider within a Pulumi program. This involves configuring the provider so that Pulumi can interact with the Rancher API. Then, we'll be able to define resources such as namespaces, catalog apps (which represent Helm charts), and other necessary Rancher constructs.Before we write the code, ensure that you have:
- Pulumi CLI installed.
- Rancher Server running and accessible.
- The
kubeconfig
file to connect to your Rancher cluster. - Helm chart name and any custom values you want to apply.
In this Pulumi program, we'll use the
rancher2
package to configure and deploy a Helm chart on Rancher. Let's write a Pulumi program that accomplishes the deployment. This will involve:- Importing the necessary Pulumi and Rancher2 libraries.
- Setting up the Rancher2 provider.
- Creating a namespace for the Helm chart if it does not exist.
- Deploying the
mysql-am
Helm chart into the namespace.
Here is the TypeScript code that illustrates this process:
import * as pulumi from "@pulumi/pulumi"; import * as rancher2 from "@pulumi/rancher2"; // Initialize a Rancher provider const provider = new rancher2.Provider("my-rancher-provider", { // You might need to provide other authentication properties depending on how your Rancher is set up apiURL: "https://rancher.my-domain.com/v3", tokenKey: "token-xxxx", // Replace with your Rancher API token }); // Create a namespace for the MySQL Helm chart if it does not already exist const namespace = new rancher2.Namespace("mysql-namespace", { name: "mysql-namespace", projectId: "c-xxxxx:p-yyyyy", // Replace with your Project ID resourceQuota: { limit: { pods: "10", secrets: "20", }, }, }, { provider: provider }); // Define the custom values for the Helm chart const mysqlValues = ` persistence: size: 8Gi image: tag: 5.7 `; // Deploy the Helm chart using the rancher2 package const mysqlHelmChart = new rancher2.CatalogV2("mysql-helm-chart", { clusterId: "c-xxxxx", // Replace with your Cluster ID name: "mysql-am", repoName: "my-helm-charts", // Name of the Rancher catalog chartName: "mysql-am", chartVersion: "1.0.0", // Specify the version of the chart namespaceId: namespace.id, // Use the ID of the namespace we created valuesYaml: mysqlValues, }, { provider: provider }); // Export the endpoint to access the deployed MySQL export const mysqlEndpoint = "mysql-service." + namespace.name + ".svc.cluster.local";
This program starts by importing Pulumi and the Rancher2 library. It then prepares the Rancher provider with the necessary endpoint and authentication token.
Next, we define a new namespace where the
mysql-am
Helm chart will be deployed, along with the resource quotas for the namespace. In a real-world scenario, adjust theprojectId
and resource quota limits to your preferences.The custom values for the MySQL Helm chart are defined in the
mysqlValues
YAML string. These can include any configurations that the Helm chart supports, such as persistence settings or image tags.We then declare a
CatalogV2
resource, which represents the Helm chart deployment. It requires specifying the chart name, chart version, and other details. TheclusterId
,repoName
, andnamespaceId
should align with your Rancher setup.Finally, we export a fictitious endpoint assuming that the Helm chart creates a Kubernetes Service named
mysql-service
in the namespace. In a real scenario, you need to obtain the appropriate Service endpoint from Rancher or Kubernetes.After coding, you would use the Pulumi CLI to deploy these resources to your Rancher cluster. Remember to ensure that you are authenticated to both Pulumi and Rancher before running Pulumi commands and adjust the values as per your Rancher setup and the specifics of the
mysql-am
Helm chart you're deploying.