Make node count and machine type configurable
MODIFY
gcp-ts-gke/README.md
gcp-ts-gke/README.md
@@ -34,6 +34,16 @@ After cloning this repo, `cd` into it and run these commands. A GKE Kubernetes c
$ pulumi config set password --secret [your-cluster-password-here]
```
+ By default, your cluster will have 3 nodes of type `n1-standard-1`. This is configurable, however; for instance
+ if we'd like to choose 5 nodes of type `n1-standard-2` instead, we can run these commands:
+
+ ```bash
+ $ pulumi config set nodeCount 5
+ $ pulumi config set nodeMachineType n1-standard-2
+ ```
+
+ This shows how stacks can be configurable in useful ways. You can even change these after provisioning.
+
3. Deploy everything with the `pulumi up` command. This provisions all the GCP resources necessary, including
your GKE cluster itself, and then deploys a Kubernetes Deployment running nginx, all in a single gesture:

MODIFY
gcp-ts-gke/cluster.ts
gcp-ts-gke/cluster.ts
import * as gcp from "@pulumi/gcp";
import * as k8s from "@pulumi/kubernetes";
import * as pulumi from "@pulumi/pulumi";
-import { password, username } from "./config";
+import { nodeCount, nodeMachineType, password, username } from "./config";
// Create the GKE cluster and export it.
export const k8sCluster = new gcp.container.Cluster("gke-cluster", {
- initialNodeCount: 3,
+ initialNodeCount: nodeCount,
nodeVersion: "latest",
minMasterVersion: "latest",
masterAuth: { username, password },
nodeConfig: {
+ machineType: nodeMachineType,
oauthScopes: [
"https://www.googleapis.com/auth/compute",
"https://www.googleapis.com/auth/devstorage.read_only",

MODIFY
gcp-ts-gke/config.ts
gcp-ts-gke/config.ts
@@ -4,6 +4,13 @@ import { Config } from "@pulumi/pulumi";
const config = new Config();
+// nodeCount is the number of cluster nodes to provision. Defaults to 3 if unspecified.
+export const nodeCount = config.getNumber("nodeCount") || 3;
+
+// nodeMachineType is the machine type to use for cluster nodes. Defaults to n1-standard-1 if unspecified.
+// See https://cloud.google.com/compute/docs/machine-types for more details on available machine types.
+export const nodeMachineType = config.get("nodeMachineType") || "n1-standard-1";
+
// username is the admin username for the cluster.
export const username = config.get("username") || "admin";

Make node count and machine type configurable