-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial implementation of Guestbook example #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/bin/ | ||
/node_modules/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: guestbook | ||
runtime: nodejs | ||
description: Kubernetes Guestbook example based on https://kubernetes.io/docs/tutorials/stateless-application/guestbook/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
// Copyright 2016-2018, Pulumi Corporation. All rights reserved. | ||
|
||
import * as pulumi from "pulumi"; | ||
import * as kubernetes from "@pulumi/kubernetes"; | ||
|
||
// REDIS MASTER | ||
|
||
let redisMasterLabels = { app: "redis", tier: "backend", role: "master"}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, variable reuse 😀 |
||
let redisMasterService = new kubernetes.Service("redis-master", { | ||
metadata: [{ | ||
name: "redis-master", | ||
labels: [redisMasterLabels], | ||
}], | ||
spec: [{ | ||
port: [{ port: 6379, targetPort: 6379 }], | ||
selector: [redisMasterLabels], | ||
}], | ||
}); | ||
let redisMasterDeployment = new kubernetes.Deployment("redis-master", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding Ksonnet, it's interesting that they got the creation of services down to a single line, and it's done by the service borrowing fields from the deployment:
I assume that's just a simple helper library? Is there any way to get this cheaply "inline" in this file? |
||
metadata: [{ | ||
name: "redis-master", | ||
}], | ||
spec: [{ | ||
selector: [redisMasterLabels], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't see the selector in the YAML/Ksonnet example. Is this correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry guess I totally missed that! |
||
replicas: 1, | ||
template: [{ | ||
metadata: [{ | ||
labels: [redisMasterLabels], | ||
}], | ||
spec: [{ | ||
container: [{ | ||
name: "master", | ||
image: "k8s.gcr.io/redis:e2e", | ||
resources: [{ | ||
requests: [{ | ||
cpu: "100m", | ||
memory: "100Mi", | ||
}] | ||
}], | ||
port: [{ | ||
containerPort: 6379, | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Believe it or not, this is one area where YAML looks nicer, more concise! (Cascading Perhaps gets better with Python. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - this is fairly ugly relative to YAML. It does have the benefit of type checking, intellisense, etc. in TypeScript - which is a slight win. I think we really need to find ways to (a) introduce some named types for common JSON sections and encourage reuse (b) create abstractions for common patterns. |
||
|
||
// REDIS SLAVE | ||
let redisSlaveLabels = { app: "redis", tier: "backend", role: "slave" }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth making this an array? I.e., There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we fix pulumi/pulumi-terraform#37 the arrays will go away - that's why I did it this way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
let redisSlaveService = new kubernetes.Service("redis-slave", { | ||
metadata: [{ | ||
name: "redis-slave", | ||
labels: [redisSlaveLabels], | ||
}], | ||
spec: [{ | ||
port: [{ port: 6379, targetPort: 6379 }], | ||
selector: [redisSlaveLabels], | ||
}], | ||
}); | ||
let redisSlaveDeployment = new kubernetes.Deployment("redis-slave", { | ||
metadata: [{ | ||
name: "redis-slave", | ||
}], | ||
spec: [{ | ||
selector: [redisSlaveLabels], | ||
replicas: 1, | ||
template: [{ | ||
metadata: [{ | ||
labels: [redisSlaveLabels], | ||
}], | ||
spec: [{ | ||
container: [{ | ||
name: "slave", | ||
image: "gcr.io/google_samples/gb-redisslave:v1", | ||
resources: [{ | ||
requests: [{ | ||
cpu: "100m", | ||
memory: "100Mi", | ||
}] | ||
}], | ||
env: [{ | ||
name: "GET_HOSTS_FROM", | ||
value: "dns", | ||
// If your cluster config does not include a dns service, then to instead access an environment | ||
// variable to find the master service's host, comment out the 'value: dns' line above, and | ||
// uncomment the line below: | ||
// value: "env" | ||
}], | ||
port: [{ | ||
containerPort: 6379, | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}); | ||
|
||
// FRONTEND | ||
let frontendLabels = { app: "guestbook", tier: "frontend" }; | ||
let frontendService = new kubernetes.Service("frontend", { | ||
metadata: [{ | ||
name: "frontend", | ||
labels: [frontendLabels], | ||
}], | ||
spec: [{ | ||
// If your cluster supports it, uncomment the following to automatically create | ||
// an external load-balanced IP for the frontend service. | ||
// type: LoadBalancer | ||
port: [{ port: 80 }], | ||
selector: [frontendLabels], | ||
}], | ||
}); | ||
let frontendDeployment = new kubernetes.Deployment("frontend", { | ||
metadata: [{ | ||
name: "frontend", | ||
}], | ||
spec: [{ | ||
selector: [frontendLabels], | ||
replicas: 3, | ||
template: [{ | ||
metadata: [{ | ||
labels: [frontendLabels], | ||
}], | ||
spec: [{ | ||
container: [{ | ||
name: "php-redis", | ||
image: "gcr.io/google-samples/gb-frontend:v4", | ||
resources: [{ | ||
requests: [{ | ||
cpu: "100m", | ||
memory: "100Mi", | ||
}] | ||
}], | ||
env: [{ | ||
name: "GET_HOSTS_FROM", | ||
value: "dns", | ||
// If your cluster config does not include a dns service, then to instead access an environment | ||
// variable to find the master service's host, comment out the 'value: dns' line above, and | ||
// uncomment the line below: | ||
// value: "env" | ||
}], | ||
port: [{ | ||
containerPort: 80, | ||
}], | ||
}], | ||
}], | ||
}], | ||
}], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "guestbook", | ||
"version": "0.1", | ||
"main": "bin/index.js", | ||
"typings": "bin/index.d.ts", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^9.3.0", | ||
"typescript": "^2.5.3" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/kubernetes": "*", | ||
"pulumi": "*" | ||
}, | ||
"license": "MIT" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@types/node@^9.3.0": | ||
version "9.4.0" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.0.tgz#b85a0bcf1e1cc84eb4901b7e96966aedc6f078d1" | ||
|
||
typescript@^2.5.3: | ||
version "2.7.1" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.1.tgz#bb3682c2c791ac90e7c6210b26478a8da085c359" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of a single file, is it worth breaking this apart more similar to https://github.com/kubernetes/kubernetes/tree/master/examples/guestbook? Feels like this will make it a little easier to consume in addition to being more familiar to those who have seen that example code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, there's a Ksonnet example here https://github.com/ksonnet/ksonnet/blob/master/examples/guestbook.jsonnet which is a single file. May be worth looking at that for inspiration for what "abstractions", if any, might make sense to introduce in the name of shrinking the example even further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's only separate files in the default
guestbook
example so that the tutorial can deploy one part at a time and talk about it that way. Like in the ksonnet version, I'd rather find ways to introduce abstractions to simplify the existing code so that it's easier to read in one file. It's rather insane the mount of text needed to do what is logically a very simple set of work here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I wrote this before looking at the Ksonnet example and I definitely like the idea of using abstractions to simplify to the point where it obviously belongs in one file 😄