Deploy the pure-k8s-plugin helm chart on Google Kubernetes Engine (GKE)
TypeScriptTo deploy a Helm chart for the
pure-k8s-plugin
on Google Kubernetes Engine (GKE), we will need to create a GKE cluster first and then deploy the Helm chart to it. To manage these resources, we will use Pulumi's Google Cloud (gcp
) and Kubernetes (kubernetes
) providers.Here are the following steps we’ll take in our Pulumi program:
- Set up a new GKE cluster.
- Use the
kubernetes
provider to deploy thepure-k8s-plugin
Helm chart to the cluster.
Below is a detailed explanation followed by the TypeScript program:
- The
gcp.container.Cluster
resource from the@pulumi/gcp
package will be used to provision a new GKE cluster. - Next, we instantiate a
kubernetes.Provider
that uses the kubeconfig from the newly created GKE cluster. - A
kubernetes.helm.v3.Chart
resource will deploy thepure-k8s-plugin
Helm chart using the Kubernetes provider that targets our GKE cluster.
The
pure-k8s-plugin
Helm chart will need to be available in a Helm repository or you must specify the chart’s location. In this example, we’ll assume that the chart is available in a public repository.Let’s start with the code:
import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; import * as k8s from "@pulumi/kubernetes"; // Step 1: Create a GKE cluster const cluster = new gcp.container.Cluster("gke-cluster", { initialNodeCount: 2, // Minimum required nodes nodeVersion: "latest", minMasterVersion: "latest", nodeConfig: { // Define compute resources for the nodes 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" ] } }); // Step 2: Configure Kubernetes provider to use the created GKE cluster const k8sProvider = new k8s.Provider("k8s-provider", { kubeconfig: cluster.endpoint.apply(endpoint => JSON.stringify({ "apiVersion": "v1", "clusters": [{ "cluster": { "certificate-authority-data": cluster.masterAuth[0].clusterCaCertificate, "server": `https://${endpoint}` }, "name": "kubernetes" }], "contexts": [{ "context": { "cluster": "kubernetes", "user": "admin" }, "name": "admin@kubernetes" }], "current-context": "admin@kubernetes", "kind": "Config", "preferences": {}, "users": [{ "name": "admin", "user": { "auth-provider": { "config": { "cmd-args": "config config-helper --format=json", "cmd-path": gcp.config.gcloudPath || "/usr/lib/google-cloud-sdk/bin/gcloud", "expiry-key": "{.credential.token_expiry}", "token-key": "{.credential.access_token}" }, "name": "gcp" } } }] })) }); // Step 3: Deploy the pure-k8s-plugin Helm chart const pureK8sPluginChart = new k8s.helm.v3.Chart("pure-k8s-plugin-chart", { chart: "pure-k8s-plugin", // Replace with the actual repository where the Helm chart is hosted fetchOpts: { repo: "https://helm-repository-url/where/chart-is-located" } }, { provider: k8sProvider }); // Export the Kubeconfig and cluster name export const kubeconfig = k8sProvider.kubeconfig; export const gkeClusterName = cluster.name;
In this program:
- A new GKE cluster is set up with two nodes of type
n1-standard-1
. The nodes are given the necessary OAuth scopes to provide access to compute, storage, logging, and monitoring services on Google Cloud. - The Kubernetes provider is configured using the GKE cluster's endpoint and its master authentication certificate.
- The
pure-k8s-plugin
Helm chart is deployed to the GKE cluster that was provisioned in step 1. Specifics for the Helm chart such as the repository URL should be replaced with the actual values relevant to thepure-k8s-plugin
Helm chart you are deploying.
Finally, the program exports the kubeconfig, which can be used to access the cluster with
kubectl
, and the name of the GKE cluster.Note that to run this Pulumi program, you will need to have Pulumi CLI installed, and have an authenticated GCP account with the necessary permissions to create resources and deploy to GKE.