Deploy the cnp-controller helm chart on Rancher
TypeScriptTo deploy the
cnp-controller
helm chart on a Rancher-managed Kubernetes cluster using Pulumi, we would typically use therancher2
provider to interact with Rancher's API. However, in the current Pulumi Registry results, there is no direct reference to deploying a Helm chart through the Rancher provider explicitly.Instead, we will use the
helm
provider from Pulumi which allows us to deploy Helm charts directly to a Kubernetes cluster. To connect to the Kubernetes cluster managed by Rancher, we'll need to set up the Kubernetes provider with the appropriate configuration (kubeconfig) obtained from Rancher.Here's a Pulumi TypeScript program that illustrates how you can deploy a Helm chart on a Kubernetes cluster:
import * as pulumi from "@pulumi/pulumi"; import * as k8s from "@pulumi/kubernetes"; // Fetch the kubeconfig from Rancher. In a real-world scenario, the kubeconfig // needs to be securely obtained and it is outside the scope of this example. const kubeconfig = `...`; // Your kubeconfig content obtained from Rancher // Create a Kubernetes provider instance using the kubeconfig from Rancher. const clusterProvider = new k8s.Provider("rancher-cluster", { kubeconfig }); // Now you can define the Helm chart resource to deploy using the provider created above. const cnpControllerChart = new k8s.helm.v3.Chart("cnp-controller", { // The repository where the Helm chart is located. // This needs to be changed to the actual repository hosting the `cnp-controller` chart. repo: "helm-repository-where-chart-is-hosted", // The name of the chart to install. chart: "cnp-controller", // Optionally, you can specify a version for the chart, ensuring an exact match. version: "chart-version", // e.g., "1.2.3" // If the Helm chart requires custom values, provide them here. values: { // ... custom values }, }, { provider: clusterProvider }); // Export the endpoint to ensure the application URL is easily accessible. // This depends on the specifics of the cnp-controller chart and might need adjustments. export const endpoint = cnpControllerChart.getResourceProperty("v1/Service", "cnp-controller-service", "status").apply(status => status.loadBalancer.ingress[0].hostname);
Explanation
- We import the
@pulumi/pulumi
and@pulumi/kubernetes
packages which are the core Pulumi package and the Kubernetes package, respectively. kubeconfig
is a placeholder for your actual Kubernetes configuration retrieved from Rancher (your CI/CD pipeline would handle this securely).- The
k8s.Provider
represents the Kubernetes cluster. This is initialized with the kubeconfig file so Pulumi can communicate with the cluster. - The
cnpControllerChart
is a Helm chart resource. This declaration encompasses fetching the Helm chart from the specified repository (repo
), at the specified version (version
), and using any configuration specified invalues
. - We use the
provider
key when creating thecnpControllerChart
to explicitly tell Pulumi to use the Kubernetes provider that we set up with our Rancher cluster's kubeconfig. - Finally, we have an
export
statement which is useful if yourcnp-controller
helm chart creates a Kubernetes Service of type LoadBalancer. It will export the endpoint that can be used to access thecnp-controller
. However, the exact property path to the hostname or IP might vary depending on the specifics of the deployed Helm chart and Service.
Please adjust the chart repository URL, version, and custom values to match the actual requirements of the
cnp-controller
helm chart you are using. Additionally, ensure that your kubeconfig is managed securely, especially when it comes to CI/CD integration or storing it in source control.- We import the