Deploy the pi-hole helm chart on Rancher
TypeScriptTo deploy the Pi-hole Helm chart on a Rancher-managed Kubernetes cluster using Pulumi, you will generally perform the following steps:
- Install and configure Pulumi.
- Create a new Pulumi project and stack.
- Choose the appropriate Pulumi provider to interact with Rancher.
- Define the Kubernetes cluster resource, if not already provisioned, using the Rancher2 provider.
- Configure the Helm chart resource to deploy Pi-hole.
For this explanation, we will focus on deploying the Pi-hole Helm chart onto an existing Kubernetes cluster managed by Rancher.
Prerequisites:
- Pulumi CLI is installed and configured with the necessary cloud credentials.
- The
rancher2
Pulumi provider is set up to communicate with a Rancher server. This provider allows us to interact with Rancher resources. - Helm CLI is installed to package and deploy applications on Kubernetes clusters.
- An existing Kubernetes cluster managed by Rancher is available for deploying Pi-hole.
Here's what a basic Pulumi TypeScript program to deploy the Pi-hole Helm chart might look like:
import * as rancher2 from "@pulumi/rancher2"; import * as k8s from "@pulumi/kubernetes"; // Initialize the rancher2 provider with the credentials to access the Rancher API. // This will use the default credentials from the Pulumi configuration and assume that // the Rancher is already authenticated and the cluster is set up. const rancherProvider = new rancher2.Provider("rancherProvider", { apiVersion: "2.4.x", // Specify the Rancher API version you are using }); // This is a placeholder. In a production scenario, you should retrieve your existing cluster // identifier from the Rancher UI or API. const clusterId = "my-cluster-id"; // Retrieve the existing cluster which Pi-hole will be deployed to. We are assuming that // the cluster already exists and is managed through Rancher. const cluster = rancher2.getCluster({ id: clusterId, }, { provider: rancherProvider }); // Bootstrap the provider for the selected Kubernetes cluster managed by Rancher const k8sProvider = new k8s.Provider("k8sProvider", { kubeconfig: cluster.kubeConfig, // Use the kubeconfig from the retrieved cluster }); // Define the Helm chart for Pi-hole. const piHoleChart = new k8s.helm.v3.Chart("pi-hole", { chart: "pi-hole", // the name of the chart // Ensure the chart is sourced from the official Pi-hole Helm repository fetchOpts: { repo: "https://helm.pihole.io", }, namespace: "pi-hole", // Namespace where Pi-hole should be installed // Values to set on the Helm chart. These should be aligned with what the Pi-hole chart expects. // Refer to the official Pi-hole Helm chart documentation for the specific values. values: { service: { type: "LoadBalancer", }, }, }, { provider: k8sProvider }); // Export the IP address of the Pi-hole service. This assumes the service type is 'LoadBalancer', // which will provision an external IP address. export const piHoleIpAddress = piHoleChart.getResourceProperty("v1/Service", "pi-hole/pi-hole", "status") .apply(status => status.loadBalancer.ingress[0].ip);
In this program:
- We import
@pulumi/rancher2
and@pulumi/kubernetes
to manage resources within Rancher and Kubernetes, respectively. - We create a
rancher2.Provider
instance, which authenticates against the Rancher API with the specified credentials. rancher2.getCluster
is called to obtain information about the existing Kubernetes cluster managed by Rancher.- We establish a
k8s.Provider
instance that uses the kubeconfig of the Rancher cluster for Kubernetes resource operations. - A
k8s.helm.v3.Chart
resource defines the deployment of the Pi-hole Helm chart, specifying the necessary configuration such as the namespace and values for the chart. - Finally, we export the external IP address of the Pi-hole service, which would allow you to use Pi-hole as your DNS server after deployment.
Please replace the placeholder values in the code with actual values that match your setup (e.g.,
clusterId
, API version, etc.). Additionally, you may need to adjust the Helm chart values to suit your specific configuration and preferences for Pi-hole.After writing this program in a
index.ts
file, you can deploy it by runningpulumi up
in the Pulumi project directory. It will prompt you to review and confirm the deployment. Once approved, Pulumi will provision the resources as defined in the program and output the resulting Pi-hole IP address.