Deploy the prometheus-haproxy-exporter helm chart on Digital Ocean Kubernetes Service
TypeScriptTo deploy the
prometheus-haproxy-exporter
helm chart on Digital Ocean Kubernetes Service (DOKS), you'll be creating a Pulumi program in TypeScript. The program will perform the following steps:- Provision a DigitalOcean Kubernetes cluster using the
digitalocean.KubernetesCluster
resource. - Use the
kubernetes.helm.v3.Chart
resource from the Kubernetes provider to deploy theprometheus-haproxy-exporter
helm chart on the cluster that's just been created.
Before you get started with the code, ensure you have installed Pulumi and have set up the necessary configuration for the DigitalOcean provider. This typically involves setting up the DigitalOcean Access Token in your environment variables or Pulumi configuration.
Here's a program that accomplishes the deployment:
import * as digitalocean from "@pulumi/digitalocean"; import * as k8s from "@pulumi/kubernetes"; // Create a new DigitalOcean Kubernetes cluster. const cluster = new digitalocean.KubernetesCluster("do-cluster", { region: "nyc1", version: "latest", nodePool: { name: "default", size: "s-2vcpu-2gb", nodeCount: 2, }, }); // The kubeconfig can be used to connect to the cluster. export const kubeconfig = cluster.kubeConfigs[0].rawConfig; // Create a Kubernetes provider instance that uses our cluster kubeconfig. const k8sProvider = new k8s.Provider("do-k8s-provider", { kubeconfig: kubeconfig, }); // Deploy the `prometheus-haproxy-exporter` helm chart using the Kubernetes provider. const helmChart = new k8s.helm.v3.Chart("haproxy-exporter", { chart: "prometheus-haproxy-exporter", version: "1.1.0", // specify the version you want to deploy namespace: "monitoring", // assuming you want to deploy this in the 'monitoring' namespace fetchOpts: { repo: "https://prometheus-community.github.io/helm-charts", }, }, { provider: k8sProvider }); // Export the chart name of the deployed Prometheus HAProxy Exporter. export const haproxyExporterChartName = helmChart.chart;
Explanation
-
We import the
digitalocean
andkubernetes
modules to interact with DigitalOcean and Kubernetes services. -
The
digitalocean.KubernetesCluster
resource creates a new DOKS cluster in thenyc1
region, picks the latest Kubernetes version available on DigitalOcean, and specifies the node pool configuration (in this case, 2 nodes of sizes-2vcpu-2gb
). -
kubeconfig
is exported, which holds the configuration needed to connect to your cluster withkubectl
or any Kubernetes client. You’d use this to interact with your Kubernetes cluster once it's provisioned. -
A
k8s.Provider
is created with the obtainedkubeconfig
. This provider is used to deploy resources to your cluster. -
The
k8s.helm.v3.Chart
resource is then used to deploy theprometheus-haproxy-exporter
helm chart to the Kubernetes cluster. -
The
repo
specified infetchOpts
is where Pulumi will fetch the Helm chart from. It's the official Helm chart repository for Prometheus. -
Optionally, you could customize the
values
property on theChart
resource to configure the HAProxy exporter according to your requirements, but it's omitted here for simplicity. -
At the end, we export some stack outputs for easy access to the deployed chart name and the
kubeconfig
.
Once you run this Pulumi program, it will provision a new Kubernetes cluster in Digital Ocean and deploy the
prometheus-haproxy-exporter
using the specified helm chart. You can retrieve the necessary output from the Pulumi stack to manage your deployment.- Provision a DigitalOcean Kubernetes cluster using the