Deploy the strimzi-drain-cleaner helm chart on Digital Ocean Kubernetes Service
TypeScriptTo deploy the Strimzi Drain Cleaner Helm chart on the Digital Ocean Kubernetes Service (DOKS), we will write a Pulumi program in TypeScript. The Strimzi Drain Cleaner is a utility which helps with graceful shutdown and eviction of Kafka pods. This program will perform the following steps:
- Provision a Kubernetes cluster on Digital Ocean using Pulumi's DigitalOcean provider.
- Deploy the Helm chart for the Strimzi Drain Cleaner on the provisioned Kubernetes cluster.
We'll use the
digitalocean.KubernetesCluster
resource to create the Kubernetes cluster in Digital Ocean, and then usekubernetes.helm.v3.Chart
from Pulumi's Kubernetes provider to deploy the Strimzi Drain Cleaner Helm chart.Below is the TypeScript program that accomplishes this. Make sure you have Pulumi installed and configured to use Digital Ocean as your cloud provider. You will also need to have
kubectl
configured to communicate with Digital Ocean Kubernetes clusters.import * as digitalocean from "@pulumi/digitalocean"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create a Kubernetes cluster in Digital Ocean const cluster = new digitalocean.KubernetesCluster("my-do-cluster", { region: "nyc1", version: "latest", // use the latest version or specify a specific version nodePool: { size: "s-2vcpu-2gb", name: "default", count: 3, }, }); // Step 2: Deploy the Strimzi Drain Cleaner Helm chart on the cluster const strimziDrainCleanerChart = new k8s.helm.v3.Chart("strimzi-drain-cleaner", { chart: "strimzi-drain-cleaner", version: "0.1.0", // specify the chart version you want to deploy fetchOpts: { repo: "https://strimzi.io/charts/", // official Strimzi Helm repository }, }, { provider: new k8s.Provider("k8s-provider", { kubeconfig: cluster.kubeConfigs[0].rawConfig }) }); // Export the Kubeconfig and cluster endpoint to access your cluster export const kubeconfig = cluster.kubeConfigs[0].rawConfig; export const clusterEndpoint = cluster.endpoint;
Here is what this code does:
- We import the required Pulumi packages for Digital Ocean (
@pulumi/digitalocean
) and Kubernetes (@pulumi/kubernetes
). These packages provide the necessary methods to work with resources in their respective providers. - We declare a variable
cluster
which represents our Kubernetes cluster in Digital Ocean. We use thedigitalocean.KubernetesCluster
resource constructor to define the parameters for our cluster, such as the region, Kubernetes version, and the size and number of nodes in the default node pool (DigitalOcean Kubernetes Clusters). - Next, we declare another variable
strimziDrainCleanerChart
to install the Strimzi Drain Cleaner Helm chart. Thek8s.helm.v3.Chart
resource constructor is used to define the chart name, version, and repository URL (Kubernetes Helm Chart). We associate it with our Digital Ocean Kubernetes cluster by providing thekubeconfig
we obtain from thecluster
. - Finally, we use
export
to output thekubeconfig
andclusterEndpoint
. These outputs can be used to interact with the Kubernetes cluster usingkubectl
or other Kubernetes tools.
To run this program:
- Save the above code to a file named
index.ts
. - Run
pulumi up
in the terminal in the directory where you saved yourindex.ts
file. Pulumi will execute the code and provision the resources as described.
When the deployment is complete, Pulumi will output the configuration needed to access the Kubernetes cluster. You can save this configuration to a file and set it as your
KUBECONFIG
environment variable, or use thepulumi stack output kubeconfig > kubeconfig.yaml
to create the kubeconfig file directly, allowingkubectl
and other tools to interact with your new Digital Ocean Kubernetes cluster.