This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rolling updates, ingress controllers, statefulset, volumes, jobs, cro…
…njobs and namespaces Signed-off-by: Erick Wendel <[email protected]>
- Loading branch information
1 parent
79b1f99
commit 3fbf10a
Showing
36 changed files
with
1,879 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"apiVersion": "extensions/v1beta1", | ||
"kind": "Deployment", | ||
"metadata": { | ||
"name": "api-heroes", | ||
"labels": { | ||
"version": "v1", | ||
"app": "api-heroes" | ||
} | ||
}, | ||
"spec": { | ||
"replicas": 2, | ||
"strategy": { | ||
"type": "RollingUpdate", | ||
"rollingUpdate": { | ||
"maxSurge": 1, | ||
"maxUnavailable": 1 | ||
} | ||
}, | ||
"minReadySeconds": 5, | ||
"selector": { | ||
"matchLabels": { | ||
"version": "v1", | ||
"app": "api-heroes" | ||
} | ||
}, | ||
"template": { | ||
"metadata": { | ||
"labels": { | ||
"version": "v1", | ||
"app": "api-heroes" | ||
} | ||
}, | ||
"spec": { | ||
"containers": [ | ||
{ | ||
"name": "api-heroes", | ||
"image": "k8scourse.azurecr.io/api-heroes:3", | ||
"ports": [ | ||
{ | ||
"containerPort": 4000 | ||
} | ||
], | ||
"env": [ | ||
{ | ||
"name": "MONGO_URL", | ||
"value": "mongodb-svc" | ||
}, | ||
{ | ||
"name": "PORT", | ||
"value": "4000" | ||
} | ||
], | ||
"resources": { | ||
"requests": { | ||
"memory": "64Mi", | ||
"cpu": "250m" | ||
}, | ||
"limits": { | ||
"memory": "100Mi", | ||
"cpu": "500m" | ||
} | ||
} | ||
} | ||
], | ||
"imagePullSecrets": [ | ||
{ | ||
"name": "acr-credentials" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
module-10 - rolling updates/nodejs-with-mongodb-api-example/.dockerignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
lib/ | ||
package-lock.json |
3 changes: 3 additions & 0 deletions
3
module-10 - rolling updates/nodejs-with-mongodb-api-example/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
lib/ | ||
package-lock.json |
13 changes: 13 additions & 0 deletions
13
module-10 - rolling updates/nodejs-with-mongodb-api-example/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM node:8-alpine | ||
|
||
ADD . /src | ||
|
||
WORKDIR /src | ||
|
||
RUN npm i -g typescript | ||
|
||
RUN npm i | ||
|
||
RUN npm run build | ||
|
||
CMD npm start |
15 changes: 15 additions & 0 deletions
15
module-10 - rolling updates/nodejs-with-mongodb-api-example/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
## Node.js with MongoDB Example | ||
|
||
<img src=https://i.imgur.com/eDNZeqh.png alt='Swagger Page of that application' title='Swagger Page of that application'/> | ||
|
||
### Requirements | ||
|
||
* Node.js v7+ | ||
* MongoDB running on local instance | ||
|
||
### Running | ||
|
||
* Install dependencies - `npm i` | ||
* Build typescript - `npm run build` | ||
* Run project - `npm start` | ||
* Go to swagger page - `localhost:3000/documentation` |
16 changes: 16 additions & 0 deletions
16
module-10 - rolling updates/nodejs-with-mongodb-api-example/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: '3' | ||
services: | ||
api-heroes: | ||
# build: . | ||
image: erickwendel/api-heroes | ||
ports: | ||
- 3000:3000 | ||
environment: | ||
MONGO_URL: mongodb | ||
links: | ||
- mongodb | ||
|
||
mongodb: | ||
image: mongo:3.5 | ||
ports: | ||
- 27017:2017 |
86 changes: 86 additions & 0 deletions
86
module-10 - rolling updates/nodejs-with-mongodb-api-example/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import * as Hapi from "hapi"; | ||
import * as Joi from "joi"; | ||
import { MongoClient } from "mongodb"; | ||
|
||
const Inert = require("inert"); | ||
const Vision = require("vision"); | ||
const HapiSwagger = require("hapi-swagger"); | ||
const server = new Hapi.Server(); | ||
const port = process.env.PORT || 3000; | ||
server.connection({ port }); | ||
|
||
(async () => { | ||
const connectionString = `mongodb://${process.env.MONGO_URL || | ||
"localhost"}/heroes`; | ||
const connection = await MongoClient.connect(connectionString); | ||
console.log("mongo db is running"); | ||
const db = connection.db("heroes").collection("hero"); | ||
await server.register([ | ||
Inert, | ||
Vision, | ||
{ | ||
register: HapiSwagger, | ||
options: { | ||
info: { | ||
title: "V3 Node.js with MongoDB Example - Erick Wendel - Updated", | ||
version: "3.0", | ||
}, | ||
}, | ||
}, | ||
]); | ||
|
||
server.route([ | ||
{ | ||
method: "GET", | ||
path: "/heroes", | ||
config: { | ||
handler: (req: any, reply: any) => { | ||
return reply(db.find().toArray()); | ||
}, | ||
description: "List All heroes", | ||
notes: "heroes from database", | ||
tags: ["api"], | ||
}, | ||
}, | ||
{ | ||
method: "POST", | ||
path: "/heroes", | ||
config: { | ||
handler: (req, reply) => { | ||
const { payload } = req; | ||
return reply(db.insert(payload)); | ||
}, | ||
description: "Create a hero", | ||
notes: "create a hero", | ||
tags: ["api"], | ||
validate: { | ||
payload: { | ||
name: Joi.string().required(), | ||
power: Joi.string().required(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
{ | ||
method: "DELETE", | ||
path: "/heroes/{id}", | ||
config: { | ||
handler: (req, reply) => { | ||
return reply(db.remove({ _id: req.params.id })); | ||
}, | ||
description: "Delete a hero", | ||
notes: "Delete a hero", | ||
tags: ["api"], | ||
validate: { | ||
params: { | ||
id: Joi.string().required(), | ||
}, | ||
}, | ||
}, | ||
}, | ||
]); | ||
|
||
await server.start(); | ||
console.log("server running at", port); | ||
})(); |
26 changes: 26 additions & 0 deletions
26
module-10 - rolling updates/nodejs-with-mongodb-api-example/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "docker-registry", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"preinstall": "npm i -g typescript", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "node lib/index.js", | ||
"build": "tsc" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@types/hapi": "^15.0.2", | ||
"@types/joi": "^13.0.5", | ||
"@types/mongodb": "^3.0.5", | ||
"hapi": "^15.2.0", | ||
"hapi-swagger": "^7.10.0", | ||
"inert": "^4.2.1", | ||
"joi": "^13.1.2", | ||
"mongodb": "^3.0.3", | ||
"vision": "^4.1.1" | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
module-10 - rolling updates/nodejs-with-mongodb-api-example/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Basic Options */ | ||
"target": | ||
"es2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */, | ||
"module": | ||
"commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | ||
"lib": [ | ||
"es2015" | ||
] /* Specify library files to be included in the compilation: */, | ||
// "allowJs": true, /* Allow javascript files to be compiled. */ | ||
// "checkJs": true, /* Report errors in .js files. */ | ||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||
// "declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
// "sourceMap": true, /* Generates corresponding '.map' file. */ | ||
// "outFile": "./", /* Concatenate and emit output to single file. */ | ||
"outDir": "lib" /* Redirect output structure to the directory. */, | ||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
// "removeComments": true, /* Do not emit comments to output. */ | ||
// "noEmit": true, /* Do not emit outputs. */ | ||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
|
||
/* Strict Type-Checking Options */ | ||
"strict": false /* Enable all strict type-checking options. */ | ||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
// "strictNullChecks": true, /* Enable strict null checks. */ | ||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */ | ||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ | ||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
|
||
/* Additional Checks */ | ||
// "noUnusedLocals": true, /* Report errors on unused locals. */ | ||
// "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
|
||
/* Module Resolution Options */ | ||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ | ||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ | ||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
// "typeRoots": [], /* List of folders to include type definitions from. */ | ||
// "types": [], /* Type declaration files to be included in compilation. */ | ||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
|
||
/* Source Map Options */ | ||
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ | ||
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ | ||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ | ||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||
|
||
/* Experimental Options */ | ||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ | ||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
kubectl create -f nginx.yaml | ||
kubectl get deployment | ||
|
||
# "spec": { | ||
# "replicas": 3, | ||
# "selector": { | ||
# "matchLabels": { | ||
# "version": "v1", | ||
# "app": "api-heroes" | ||
# } | ||
# }, | ||
kubectl apply -f heroes-deploy.json --record | ||
kubectl get deploy api-heroes | ||
kubectl rollout history deployment api-heroes | ||
kubectl rollout status deployment api-heroes | ||
kubectl rollout undo deployment api-heroes --to-revision=1 | ||
kubectl set image deployment api-heroes api-heroes=k8scourse.azurecr.io/api-heroes:3 --record | ||
|
||
kubectl replace -f heroes-deploy.json --record | ||
kubectl edit deployment api-heroes --record | ||
|
||
kubectl rollout pause deployment api-heroes | ||
kubectl rollout resume deployment api-heroes |
35 changes: 35 additions & 0 deletions
35
module-11 - ingress controllers/1. nginx-default-backend.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: nginx-default-backend | ||
spec: | ||
ports: | ||
- port: 80 | ||
targetPort: http | ||
selector: | ||
app: nginx-default-backend | ||
--- | ||
kind: Deployment | ||
apiVersion: extensions/v1beta1 | ||
metadata: | ||
name: nginx-default-backend | ||
spec: | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: nginx-default-backend | ||
spec: | ||
terminationGracePeriodSeconds: 60 | ||
containers: | ||
- name: default-http-backend | ||
image: gcr.io/google_containers/defaultbackend:1.0 | ||
livenessProbe: | ||
httpGet: | ||
path: /healthz | ||
port: 8080 | ||
scheme: HTTP | ||
initialDelaySeconds: 30 | ||
timeoutSeconds: 5 | ||
ports: | ||
- containerPort: 8080 |
Oops, something went wrong.