Skip to content

Commit

Permalink
Update k8s examples (pulumi#400)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
lblackstone committed Sep 19, 2019
1 parent 21e672e commit 9d9fc3d
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion aws-ts-eks-hello-world/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
1 change: 0 additions & 1 deletion gcp-ts-gke-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions gcp-ts-gke-hello-world/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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;
2 changes: 1 addition & 1 deletion gcp-ts-gke/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions gcp-ts-gke/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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();

Expand All @@ -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;
2 changes: 1 addition & 1 deletion gcp-ts-gke/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion gcp-ts-gke/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"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"
}
}
4 changes: 2 additions & 2 deletions kubernetes-ts-configmap-rollout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions kubernetes-ts-exposed-deployment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions kubernetes-ts-guestbook/components/k8sjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion kubernetes-ts-guestbook/simple/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions kubernetes-ts-s3-rollout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
26 changes: 13 additions & 13 deletions kubernetes-ts-sock-shop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 9d9fc3d

Please sign in to comment.