Deploy the growthbook helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy the GrowthBook Helm chart on Google Kubernetes Engine (GKE), you will first need to create a GKE cluster and then use the Helm package manager to install the GrowthBook chart onto your cluster. Below you'll find a detailed explanation and a full Pulumi program written in TypeScript that accomplishes this task.
Creating a GKE Cluster
You'll create a GKE cluster using Pulumi's GCP provider. This provider offers abstractions that allow you to conveniently create, configure, and manage Google Cloud resources.
The following resource will be used:
gcp.container.Cluster
: This creates a Kubernetes cluster in GCP.
Installing the GrowthBook Helm Chart
After setting up the GKE cluster, you'll install the GrowthBook Helm Chart. You will use the Helm Release resource from the
@pulumi/kubernetes
package which allows you to use Helm charts.The following resource will be used:
kubernetes.helm.v3.Chart
: This resource represents a Helm chart release, which is used to deploy containerized applications using the Helm package manager.
Now, here is the complete Pulumi program that performs these tasks:
import * as pulumi from '@pulumi/pulumi'; import * as gcp from '@pulumi/gcp'; import * as k8s from '@pulumi/kubernetes'; // Create a GKE cluster const cluster = new gcp.container.Cluster("growthbook-cluster", { initialNodeCount: 2, minMasterVersion: 'latest', nodeVersion: 'latest', nodeConfig: { machineType: "n1-standard-1", 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 Kubeconfig export const kubeconfig = 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 `; }); // Use kubeconfig from cluster to create a provider const provider = new k8s.Provider("gke-k8s", { kubeconfig: kubeconfig, }); // Install GrowthBook Helm Chart const growthbookChart = new k8s.helm.v3.Chart("growthbook", { chart: "growthbook", version: "0.1.0", // specify the version of the chart fetchOpts: { repo: "https://charts.growthbook.io", // specify the Helm chart repository }, }, { provider: provider }); // Export the Helm chart resources export const helmChartResources = growthbookChart.resources;
How the Program Works
- The GKE cluster
growthbook-cluster
is created with 2 nodes using thegcp.container.Cluster
resource. The nodes are of typen1-standard-1
, which refers to a standard machine type with 1 vCPU and 3.75 GB of memory. - The
kubeconfig
is exported, which you would use to interact with your cluster viakubectl
. This configuration includes credentials to communicate with the master endpoint securely. - A new
k8s.Provider
is created, which uses the exportedkubeconfig
to communicate with the Kubernetes cluster on GKE. - The
k8s.helm.v3.Chart
resource namedgrowthbook
refers to the GrowthBook Helm chart, which is fetched from the specified repository. Replace"0.1.0"
with the actual version of the GrowthBook Helm chart you wish to deploy.
Once you've applied this Pulumi program, the GKE cluster will be provisioned, and upon successful creation, the GrowthBook Helm chart will be deployed to it.
Remember to replace the dummy values such as
chart
version andrepo
URL with actual values corresponding to the GrowthBook chart you are deploying. You may need to get these details from the official GrowthBook Helm chart documentation or repository.Lastly, save this code to a
index.ts
file in your Pulumi project directory and follow the usual Pulumi workflow to preview and deploy the changes using commandspulumi up
in your terminal.