├── .gitignore ├── LICENSE.md ├── README.md ├── docs └── images │ ├── container-banner.png │ └── kubernetes-relationships.png └── sample-app ├── .dockerignore ├── .gitignore ├── Dockerfile ├── package.json ├── sample-app.deployment-service.yml └── server.js /.gitignore: -------------------------------------------------------------------------------- 1 | conf/certs/*.crt 2 | conf/certs/*.key 3 | conf/nginx/htpasswd -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright (c) 2018 NodeSource 5 | ----------------------------- 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Node.js, Docker, and Kubernetes](docs/images/container-banner.png)](https://nodesource.com/) 2 | 3 | ## Overview 4 | 5 | This repository is for deploying a simple [Node.js](https://nodejs.org/en/) application with [Kubernetes](http://kubernetes.io/) to [Gogle Kubernetes Engine](https://cloud.google.com/kubernetes-engine/), and accompanies a [detailed article]() on the [NodeSource](https://nodesource.com) [blog](https://nodesource/com/blog). 6 | 7 | ![Kubernetes Relationships](docs/images/kubernetes-relationships.png) 8 | -------------------------------------------------------------------------------- /docs/images/container-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nodesource/simple-nodejs-k8s/94e342561eba10135a7e9bd7ec89847728da8cb2/docs/images/container-banner.png -------------------------------------------------------------------------------- /docs/images/kubernetes-relationships.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nodesource/simple-nodejs-k8s/94e342561eba10135a7e9bd7ec89847728da8cb2/docs/images/kubernetes-relationships.png -------------------------------------------------------------------------------- /sample-app/.dockerignore: -------------------------------------------------------------------------------- 1 | app-controller.yaml 2 | app-service.yaml 3 | node_modules -------------------------------------------------------------------------------- /sample-app/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /sample-app/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8 2 | 3 | RUN mkdir -p /usr/src/app 4 | 5 | WORKDIR /usr/src/app 6 | 7 | ADD package.json /usr/src/app/package.json 8 | RUN npm install --production 9 | ADD server.js /usr/src/app/server.js 10 | 11 | ENTRYPOINT ["node", "server.js"] 12 | -------------------------------------------------------------------------------- /sample-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sample-app", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node server.js" 9 | }, 10 | "author": "", 11 | "license": "MIT", 12 | "dependencies": { 13 | "moment": "2.19.3", 14 | "qs": "2.2.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sample-app/sample-app.deployment-service.yml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: Deployment 3 | metadata: 4 | name: sample-app 5 | labels: 6 | app: sample-app 7 | spec: 8 | replicas: 1 9 | template: 10 | metadata: 11 | labels: 12 | app: sample-app 13 | spec: 14 | containers: 15 | - name: sample-app 16 | image: ${dockerHubUsername}/sample-app:v1 17 | env: 18 | - name: APP_NAME 19 | value: "sample-app" 20 | - name: TEST_ME 21 | value: "Hello, world!" 22 | - name: K8_NODE 23 | valueFrom: 24 | fieldRef: 25 | fieldPath: spec.nodeName 26 | - name: K8_POD 27 | valueFrom: 28 | fieldRef: 29 | fieldPath: metadata.name 30 | - name: K8_NS 31 | valueFrom: 32 | fieldRef: 33 | fieldPath: metadata.namespace 34 | - name: K8_IP 35 | valueFrom: 36 | fieldRef: 37 | fieldPath: status.podIP 38 | - name: PORT 39 | value: "4444" 40 | ports: 41 | - containerPort: 4444 42 | name: sample-app 43 | --- 44 | apiVersion: v1 45 | kind: Service 46 | metadata: 47 | name: sample-app 48 | spec: 49 | type: LoadBalancer 50 | ports: 51 | - port: 80 52 | targetPort: sample-app 53 | selector: 54 | app: sample-app 55 | -------------------------------------------------------------------------------- /sample-app/server.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | var os = require('os'); 3 | var hostname = os.hostname(); 4 | 5 | var qs = require('qs'); 6 | var moment = require('moment'); 7 | 8 | var port = process.env.PORT || 3000; 9 | 10 | function handleRequest (request, response) { 11 | response.end('[' + hostname + '] Serving requests from myapp. Request URL:' + request.url); 12 | } 13 | 14 | var server = http.createServer(handleRequest); 15 | 16 | server.listen(port, function () { 17 | console.log('Server listening on port', port); 18 | }); 19 | --------------------------------------------------------------------------------