Add a Google Kubernetes Engine (GKE) example
This creates a GKE cluster and then deploys a canary Kubernetes
Deployment, running nginx, into it to verify that all is well.
ADD
gcp-ts-gke/.gitignore
+/bin/
+/node_modules/

ADD
gcp-ts-gke/Pulumi.yaml
+name: gcp-ts-gke
+description: A Google Kubernetes Engine (GKE) cluster, with canary deployment
+runtime: nodejs

ADD
gcp-ts-gke/cluster.ts
+// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
+
+import * as gcp from "@pulumi/gcp";
+import * as k8s from "@pulumi/kubernetes";
+import * as pulumi from "@pulumi/pulumi";
+import { password, username } from "./config";
+
+// Create the GKE cluster and export it.
+export const k8sCluster = new gcp.container.Cluster("gke-cluster", {
+ initialNodeCount: 3,
+ nodeVersion: "latest",
+ minMasterVersion: "latest",
+ masterAuth: { username, password },
+ nodeConfig: {
+ 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"
+ ],
+ },
+});
+
+// Manufacture a GKE-style Kubeconfig. Note that this is slightly "different" because of the way GKE requires
+// gcloud to be in the picture for cluster authentication (rather than using the client cert/key directly).
+export const k8sConfig = pulumi.
+ all([ k8sCluster.name, k8sCluster.endpoint, k8sCluster.masterAuth ]).
+ apply(([ name, endpoint, auth ]) => {
+ const context = `${gcp.config.project}_${gcp.config.zone}_${name}`;
+ return `apiVersion: v1
+clusters:
+- cluster:
+ certificate-authority-data: ${auth.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
+`;
+ });
+
+// Export a Kubernetes provider instance that uses our cluster from above.
+export const k8sProvider = new k8s.Provider("gkeK8s", {
+ kubeconfig: k8sConfig,
+});

ADD
gcp-ts-gke/config.ts
+// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
+
+import { Config } from "@pulumi/pulumi";
+
+const config = new Config();
+
+// username is the admin username for the cluster.
+export const username = config.get("username") || "admin";
+
+// password is the password for the admin user in the cluster.
+export const password = config.require("password");

ADD
gcp-ts-gke/index.ts
+// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
+
+import * as k8s from "@pulumi/kubernetes";
+import * as pulumi from "@pulumi/pulumi";
+import { k8sProvider, k8sConfig } from "./cluster";
+
+// Create a canary deployment to test that this cluster works.
+const name = `${pulumi.getProject()}-${pulumi.getStack()}`;
+const canaryLabels = { app: `canary-${name}` };
+const canary = new k8s.apps.v1beta1.Deployment("canary", {
+ spec: {
+ selector: { matchLabels: canaryLabels },
+ replicas: 1,
+ template: {
+ metadata: { labels: canaryLabels },
+ spec: { containers: [{ name, image: "nginx" }] },
+ },
+ },
+}, { provider: k8sProvider });
+
+// Export the Kubeconfig so that clients can easily access our cluster.
+export let kubeConfig = k8sConfig;

ADD
gcp-ts-gke/package.json
+{
+ "name": "gcp-ts-gke",
+ "devDependencies": {
+ "@types/node": "latest"
+ },
+ "dependencies": {
+ "@pulumi/gcp": "latest",
+ "@pulumi/kubernetes": "latest",
+ "@pulumi/pulumi": "latest"
+ }
+}

ADD
gcp-ts-gke/tsconfig.json
+{
+ "compilerOptions": {
+ "outDir": "bin",
+ "target": "es6",
+ "lib": [
+ "es6"
+ ],
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitAny": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true,
+ "strictNullChecks": true
+ },
+ "files": [
+ "index.ts",
+ "config.ts",
+ "cluster.ts"
+ ]
+}

Add a Google Kubernetes Engine (GKE) example

This creates a GKE cluster and then deploys a canary Kubernetes
Deployment, running nginx, into it to verify that all is well.