Update k8s examples
* Update old apiVersions
* Remove unneeded apply's
* Improve GKE examples
Make it a little easier to use the GKE examples by autogenerating
the password and defaulting the master version to latest.
MODIFY
aws-ts-eks-hello-world/index.ts
aws-ts-eks-hello-world/index.ts
@@ -83,4 +83,4 @@ const service = new k8s.core.v1.Service(name,
// Export the Service name and public LoadBalancer Endpoint
export const serviceName = service.metadata.name;
-export const serviceHostname = service.status.apply(s => s.loadBalancer.ingress[0].hostname);
+export const serviceHostname = service.status.loadBalancer.ingress[0].hostname;

MODIFY
gcp-ts-gke-hello-world/README.md
gcp-ts-gke-hello-world/README.md
@@ -56,7 +56,6 @@ After cloning this repo, from this working directory, run these commands:
```bash
$ pulumi config set gcp:project <YOUR_GCP_PROJECT_HERE>
$ pulumi config set gcp:zone us-west1-a // any valid GCP Zone here
- $ pulumi config set masterVersion #any valid master version
```
1. Stand up the GKE cluster:

MODIFY
gcp-ts-gke-hello-world/index.ts
gcp-ts-gke-hello-world/index.ts
@@ -7,7 +7,8 @@ import * as pulumi from "@pulumi/pulumi";
const name = "helloworld";
const config = new pulumi.Config();
-export const masterVersion = config.require("masterVersion");
+export const masterVersion = config.get("masterVersion") ||
+ gcp.container.getEngineVersions().latestMasterVersion;
// Create a GKE cluster
const cluster = new gcp.container.Cluster(name, {
@@ -128,4 +129,4 @@ const service = new k8s.core.v1.Service(name,
// Export the Service name and public LoadBalancer endpoint
export const serviceName = service.metadata.name;
-export const servicePublicIP = service.status.apply(s => s.loadBalancer.ingress[0].ip);
+export const servicePublicIP = service.status.loadBalancer.ingress[0].ip;

MODIFY
gcp-ts-gke/README.md
gcp-ts-gke/README.md
@@ -34,7 +34,6 @@ After cloning this repo, `cd` into it and run these commands. A GKE Kubernetes c
$ pulumi config set gcp:project [your-gcp-project-here]
$ pulumi config set gcp:zone us-west1-a # any valid GCP zone here
$ pulumi config set password --secret [your-cluster-password-here]
- $ pulumi config set masterVersion #any valid MasterVersion
```
By default, your cluster will have 3 nodes of type `n1-standard-1`. This is configurable, however; for instance
@@ -43,6 +42,7 @@ After cloning this repo, `cd` into it and run these commands. A GKE Kubernetes c
```bash
$ pulumi config set nodeCount 5
$ pulumi config set nodeMachineType n1-standard-2
+ $ pulumi config set masterVersion #any valid MasterVersion
```
This shows how stacks can be configurable in useful ways. You can even change these after provisioning.

MODIFY
gcp-ts-gke/config.ts
gcp-ts-gke/config.ts
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.
+import * as gcp from "@pulumi/gcp";
import { Config } from "@pulumi/pulumi";
+import * as random from "@pulumi/random";
const config = new Config();
@@ -15,7 +17,10 @@ export const nodeMachineType = config.get("nodeMachineType") || "n1-standard-1";
export const username = config.get("username") || "admin";
// password is the password for the admin user in the cluster.
-export const password = config.require("password");
+// If a password is not set, a strong random password will be generated.
+export const password = config.get("password") || new random.RandomPassword(
+ "password", { length: 20, special: true }).result;
// GKE master version
-export const masterVersion = config.require("masterVersion");
+// Default to the latest available version.
+export const masterVersion = config.get("masterVersion") || gcp.container.getEngineVersions().latestMasterVersion;

MODIFY
gcp-ts-gke/index.ts
gcp-ts-gke/index.ts
@@ -7,7 +7,7 @@ import { k8sConfig, k8sProvider } 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", {
+const canary = new k8s.apps.v1.Deployment("canary", {
spec: {
selector: { matchLabels: canaryLabels },
replicas: 1,

MODIFY
gcp-ts-gke/package.json
gcp-ts-gke/package.json
"dependencies": {
"@pulumi/gcp": "^1.0.0",
"@pulumi/kubernetes": "^1.0.0",
- "@pulumi/pulumi": "^1.0.0"
+ "@pulumi/pulumi": "^1.0.0",
+ "@pulumi/random": "^1.0.0"
}
}

MODIFY
kubernetes-ts-configmap-rollout/index.ts
kubernetes-ts-configmap-rollout/index.ts
@@ -22,7 +22,7 @@ const nginxConfigName = nginxConfig.metadata.apply(m => m.name);
// Deploy 1 nginx replica, mounting the configuration data into the nginx
// container.
-const nginx = new k8s.apps.v1beta1.Deployment(appName, {
+const nginx = new k8s.apps.v1.Deployment(appName, {
metadata: { labels: appLabels },
spec: {
replicas: 1,
@@ -57,5 +57,5 @@ export let frontendIp: pulumi.Output<string>;
if (isMinikube === "true") {
frontendIp = frontend.spec.clusterIP;
} else {
- frontendIp = frontend.status.apply(status => status.loadBalancer.ingress[0].ip);
+ frontendIp = frontend.status.status.loadBalancer.ingress[0].ip;
}

MODIFY
kubernetes-ts-exposed-deployment/index.ts
kubernetes-ts-exposed-deployment/index.ts
@@ -11,7 +11,7 @@ const isMinikube = config.require("isMinikube");
// nginx container, replicated 1 time.
const appName = "nginx";
const appLabels = { app: appName };
-const nginx = new k8s.apps.v1beta1.Deployment(appName, {
+const nginx = new k8s.apps.v1.Deployment(appName, {
spec: {
selector: { matchLabels: appLabels },
replicas: 1,
@@ -37,5 +37,5 @@ export let frontendIp: pulumi.Output<string>;
if (isMinikube === "true") {
frontendIp = frontend.spec.clusterIP;
} else {
- frontendIp = frontend.status.apply(status => status.loadBalancer.ingress[0].ip);
+ frontendIp = frontend.status.loadBalancer.ingress[0].ip;
}

MODIFY
kubernetes-ts-guestbook/components/k8sjs.ts
kubernetes-ts-guestbook/components/k8sjs.ts
@@ -50,8 +50,8 @@ export class ServiceDeployment extends pulumi.ComponentResource {
if (args.allocateIpAddress) {
this.ipAddress = args.isMinikube ?
- this.service.spec.apply(spec => spec.clusterIP) :
- this.service.status.apply(status => status.loadBalancer.ingress[0].ip);
+ this.service.spec.clusterIP :
+ this.service.status.loadBalancer.ingress[0].ip;
}
}
}

MODIFY
kubernetes-ts-guestbook/simple/index.ts
kubernetes-ts-guestbook/simple/index.ts
@@ -116,5 +116,5 @@ export let frontendIp: pulumi.Output<string>;
if (isMinikube) {
frontendIp = frontendService.spec.clusterIP;
} else {
- frontendIp = frontendService.status.apply(status => status.loadBalancer.ingress[0].ip);
+ frontendIp = frontendService.status.loadBalancer.ingress[0].ip;
}

MODIFY
kubernetes-ts-s3-rollout/index.ts
kubernetes-ts-s3-rollout/index.ts
@@ -21,7 +21,7 @@ const nginxConfigMount = { name: nginxConfigVol.name, mountPath: "/etc/nginx/con
// Deploy 1 replica of nginx. Use `curl` to get `default.conf` from a public S3 bucket, which
// configures nginx to act as a proxy for `pulumi.github.io`.
-const nginx = new k8s.apps.v1beta1.Deployment("nginx", {
+const nginx = new k8s.apps.v1.Deployment("nginx", {
spec: {
replicas: 1,
template: {
@@ -55,4 +55,4 @@ const frontend = new k8s.core.v1.Service("nginx", {
});
// Export the frontend IP.
-export const frontendIp = frontend.status.apply(status => status.loadBalancer.ingress[0].ip);
+export const frontendIp = frontend.status.loadBalancer.ingress[0].ip;

MODIFY
kubernetes-ts-sock-shop/index.ts
kubernetes-ts-sock-shop/index.ts
@@ -16,7 +16,7 @@ const sockShopNs = new k8s.core.v1.Namespace("sock-shop", { metadata: { name: "s
// Carts microservice.
// -------------------------------------------------------------------------
-const cartsDb = new k8s.apps.v1beta1.Deployment("carts-db", {
+const cartsDb = new k8s.apps.v1.Deployment("carts-db", {
metadata: {
name: "carts-db",
labels: {
@@ -93,7 +93,7 @@ const cartsDbService = new k8s.core.v1.Service("carts-db", {
},
});
-const carts = new k8s.apps.v1beta1.Deployment("carts", {
+const carts = new k8s.apps.v1.Deployment("carts", {
metadata: {
name: "carts",
labels: {
@@ -186,7 +186,7 @@ const cartsService = new k8s.core.v1.Service("carts", {
// Catalog microservice.
// --------------------------------------------------------------------------
-const catalogDb = new k8s.apps.v1beta1.Deployment("catalog-db", {
+const catalogDb = new k8s.apps.v1.Deployment("catalog-db", {
metadata: {
name: "catalogue-db",
labels: {
@@ -252,7 +252,7 @@ const catalogDbService = new k8s.core.v1.Service("catalog-db", {
},
});
-const catalog = new k8s.apps.v1beta1.Deployment("catalog", {
+const catalog = new k8s.apps.v1.Deployment("catalog", {
metadata: {
name: "catalogue",
labels: {
@@ -320,7 +320,7 @@ const catalogService = new k8s.core.v1.Service("catalog", {
// Frontend microservice.
// --------------------------------------------------------------------------
-const frontend = new k8s.apps.v1beta1.Deployment("front-end", {
+const frontend = new k8s.apps.v1.Deployment("front-end", {
metadata: {
name: "front-end",
namespace: sockShopNs.metadata.name,
@@ -392,7 +392,7 @@ const frontendService = new k8s.core.v1.Service("front-end", {
// Orders microservice.
// --------------------------------------------------------------------------
-const ordersDb = new k8s.apps.v1beta1.Deployment("orders-db", {
+const ordersDb = new k8s.apps.v1.Deployment("orders-db", {
metadata: {
name: "orders-db",
labels: {
@@ -469,7 +469,7 @@ const ordersDbService = new k8s.core.v1.Service("orders-db", {
},
});
-const orders = new k8s.apps.v1beta1.Deployment("orders", {
+const orders = new k8s.apps.v1.Deployment("orders", {
metadata: {
name: "orders",
labels: {
@@ -562,7 +562,7 @@ const ordersService = new k8s.core.v1.Service("orders", {
// Payment microservice.
// --------------------------------------------------------------------------
-const payment = new k8s.apps.v1beta1.Deployment("payment", {
+const payment = new k8s.apps.v1.Deployment("payment", {
metadata: {
name: "payment",
labels: {
@@ -630,7 +630,7 @@ const paymentService = new k8s.core.v1.Service("payment", {
// Queue microservice.
// --------------------------------------------------------------------------
-const queueMaster = new k8s.apps.v1beta1.Deployment("queue-master", {
+const queueMaster = new k8s.apps.v1.Deployment("queue-master", {
metadata: {
name: "queue-master",
labels: {
@@ -688,7 +688,7 @@ const queueMasterService = new k8s.core.v1.Service("queue-master", {
},
});
-const rabbitmq = new k8s.apps.v1beta1.Deployment("rabbitmq", {
+const rabbitmq = new k8s.apps.v1.Deployment("rabbitmq", {
metadata: {
name: "rabbitmq",
labels: {
@@ -754,7 +754,7 @@ const rabbitmqService = new k8s.core.v1.Service("rabbitmq", {
// Shipping microservice.
// --------------------------------------------------------------------------
-const shipping = new k8s.apps.v1beta1.Deployment("shipping", {
+const shipping = new k8s.apps.v1.Deployment("shipping", {
metadata: {
name: "shipping",
labels: {
@@ -847,7 +847,7 @@ const shippingService = new k8s.core.v1.Service("shipping", {
// User microservice.
// --------------------------------------------------------------------------
-const userDb = new k8s.apps.v1beta1.Deployment("user-db", {
+const userDb = new k8s.apps.v1.Deployment("user-db", {
metadata: {
name: "user-db",
labels: {
@@ -924,7 +924,7 @@ const userDbService = new k8s.core.v1.Service("user-db", {
},
});
-const user = new k8s.apps.v1beta1.Deployment("user", {
+const user = new k8s.apps.v1.Deployment("user", {
metadata: {
name: "user",
labels: {

Update k8s examples (#400)

* Update old apiVersions

* Remove unneeded apply's

* Improve GKE examples

Make it a little easier to use the GKE examples by autogenerating
the password and defaulting the master version to latest.