Deploy the zookeeper-exporter helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the
zookeeper-exporter
Helm chart on Google Kubernetes Engine (GKE) using Pulumi, you will follow these steps:- Set up a new GKE cluster or use an existing one where you want to deploy your Helm chart.
- Install the Helm chart onto your GKE cluster using Pulumi's
kubernetes
package.
We'll begin by creating a GKE cluster. This requires setting up the necessary GCP resources and configurations. To do this, you will use
google-native.container.v1.Cluster
to create the cluster andgoogle-native.container.v1.NodePool
to create node pools if necessary.Once the GKE cluster is ready, you will proceed to deploy the
zookeeper-exporter
Helm chart. Thekubernetes.helm.v3.Chart
resource from the@pulumi/kubernetes
package will be used for this task. It abstracts away the complexity of deploying Helm charts.Here's the full Pulumi program written in TypeScript that accomplishes this:
import * as gcp from "@pulumi/gcp"; import * as kubernetes from "@pulumi/kubernetes"; import * as pulumi from "@pulumi/pulumi"; // Step 1: Create a GKE Cluster const cluster = new gcp.container.Cluster("gke-cluster", { initialNodeCount: 1, minMasterVersion: "latest", // Use the latest GKE version; alternatively, specify a concrete version nodeVersion: "latest", nodeConfig: { machineType: "n1-standard-1", // This is a default machine type; adjust as required oauthScopes: [ "https://www.googleapis.com/auth/compute", "https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring" ], }, }); // Export the Cluster name export const clusterName = cluster.name; // Obtain the k8s config for the newly created cluster const k8sConfig = pulumi. all([cluster.name, cluster.endpoint, cluster.masterAuth]). apply(([name, endpoint, masterAuth]) => { const context = `${gcp.config.project}_${gcp.config.zone}_${name}`; return `apiVersion: v1 clusters: - cluster: certificate-authority-data: ${masterAuth.clusterCaCertificate} server: https://${endpoint} name: ${context} contexts: - context: cluster: ${context} user: ${context} name: ${context} current-context: ${context} kind: Config preferences: {} users: - name: ${context} user: auth-provider: config: cmd-args: config config-helper --format=json cmd-path: gcloud expiry-key: '{.credential.token_expiry}' token-key: '{.credential.access_token}' name: gcp `; }); // Step 2: Deploy zookeeper-exporter Helm chart // Define the settings for our Helm chart, including the zookeeper endpoint const zookeeperExporterChart = new kubernetes.helm.v3.Chart("zookeeper-exporter", { chart: "zookeeper-exporter", version: "1.0.0", // The version of the Helm chart; replace with the desired version fetchOpts: { repo: "https://helm-repository-url", // Replace with your Helm repository URL }, values: { // Specify any custom values required for the zookeeper-exporter chart }, }, { provider: new kubernetes.Provider("gke-k8s", { kubeconfig: k8sConfig }) }); // Export the Helm chart deployment name export const zookeeperExporterChartName = zookeeperExporterChart.name;
In this program:
-
A new GKE cluster named
gke-cluster
is created. TheinitialNodeCount
specifies the number of nodes.minMasterVersion
andnodeVersion
are set tolatest
, which means it will pick the latest available version for the master and nodes, respectively. -
GKE cluster configuration including machine type and OAuth scopes are specified under
nodeConfig
. You can adjust machine types, scopes, and other settings according to your requirements. -
The k8s config is constructed for the newly created GKE cluster, which includes cluster endpoint and authentication data.
-
A new Helm chart deployment for
zookeeper-exporter
is initiated. You need to replace"https://helm-repository-url"
with the actual repository URL where yourzookeeper-exporter
Helm chart is located. -
You can specify custom values for the Zookeeper Exporter Helm chart under the
values
object in the Helm chart resource. This can include configurations specific to thezookeeper-exporter
, such as resource limits or service types.
When you run this program with Pulumi (after authenticating with GCP), it will provision a new GKE cluster and deploy the
zookeeper-exporter
Helm chart. Theexport
statements will output the GKE cluster name and Helm release name when the deployment process is completed.