Last active
July 4, 2017 11:08
-
-
Save ThijsFeryn/69c066f9ec955e40b96eab1b70c8795f to your computer and use it in GitHub Desktop.
Dockerized Hello NodeJS example to test Kubernetes
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
FROM node:6.9.2 | |
EXPOSE 8080 | |
COPY server.js . | |
CMD node server.js |
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
apiVersion: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: hello-nodejs | |
spec: | |
replicas: 2 | |
template: | |
metadata: | |
labels: | |
app: hello-nodejs | |
spec: | |
containers: | |
- image: hello-nodejs:latest | |
imagePullPolicy: IfNotPresent | |
name: hello-nodejs | |
ports: | |
- containerPort: 8080 |
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
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: hello-nodejs-service | |
spec: | |
type: NodePort | |
ports: | |
- port: 8080 | |
targetPort: 8080 | |
protocol: TCP | |
selector: | |
app: hello-nodejs |
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
#!/usr/bin/env bash | |
eval $(minikube docker-env) | |
docker build -t hello-nodejs . | |
kubectl create -f hello_nodejs_deployment.yml | |
kubectl create -f hello_nodejs_service.yml | |
curl $(minikube service hello-nodejs-service --url) |
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
var http = require('http'); | |
var handleRequest = function(request, response){ | |
console.log("rx request for url:" + request.url); | |
response.writeHead(200) | |
response.end('Hello World: ' + process.env.HOSTNAME); | |
}; | |
var www = http.createServer(handleRequest); | |
www.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment