mkdir dev
cd dev
cat > Dockerfile
FROM node:4.4
EXPOSE 8080
COPY server.js .
CMD node server.js
[press ^d to exit and save the file]
Validate Dockerfile
cat Dockerfile
cat > server.js
var http = require('http');
var handleRequest = function(request, response) {
response.writeHead(200);
response.end("Hello World!");
}
var www = http.createServer(handleRequest);
www.listen(8080);
[press ^d to exit and save the file]
docker build -t initcron/node:v1 .
Validate
docker images
docker run -d -p 9090:8080 --name nodetest initcron/node:v1
curl localhost:9090
docker rm -f nodetest
kubectl run hello-node --image=initcron/node:v1 --port=8080
Validate
kubectl get deployments
[output]
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
hello-node 1 1 1 1 9s
kubectl get pods
[output]
NAME READY STATUS RESTARTS AGE
hello-node-3739401303-9ltt5 1/1 Running 0 53s
Cluster Info
kubectl cluster-info
kubectl get events
kubectl config view
kubectl expose deployment hello-node --type="LoadBalancer"
kubectl get services
hello-node 10.0.0.50 <pending> 8080/TCP 9m
kubernetes 10.0.0.1 <none> 443/TCP 43m
nginx 10.0.0.28 <none> 80/TCP 38m
Validate
curl http://10.0.0.50:8080
kubectl scale deployment hello-node --replicas=4
kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
hello-node 4 4 4 4 5m
kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-node-3739401303-4b8qp 1/1 Running 0 23s
hello-node-3739401303-9ltt5 1/1 Running 0 6m
hello-node-3739401303-kc2u1 1/1 Running 0 23s
hello-node-3739401303-uavwk 1/1 Running 0 23s
Update Node App
cat > server.js
var http = require('http');
var handleRequest = function(request, response) {
response.writeHead(200);
response.end("Hello Kubernetes World!");
}
var www = http.createServer(handleRequest);
www.listen(8080);
[^d to exit]
Build Image
docker build -t initcron/node:v2 .
kubectl edit deployment hello-node
[ Change image to use v2 ]
Validate
# kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
hello-node 4 5 4 3 8m
kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-node-3739401303-bcsuz 1/1 Terminating 0 6m
hello-node-3739401303-gyips 1/1 Terminating 0 6m
hello-node-3739401303-zh3az 1/1 Running 0 8m
hello-node-3820797016-4opzh 1/1 Running 0 1m
hello-node-3820797016-9gdzr 0/1 ContainerCreating 0 6s
hello-node-3820797016-x1ql4 1/1 Running 0 1m
hello-node-3820797016-y30fh 0/1 ContainerCreating 0 15s
kubectl get services
AME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node 10.0.0.50 <pending> 8080/TCP 9m
kubernetes 10.0.0.1 <none> 443/TCP 43m
nginx 10.0.0.28 <none> 80/TCP 38m
curl http://10.0.0.50:8080
kubectl delete service,deployment hello-node