Deploying Node.JS "microservice" using Docker and Kubernets Cluster

Prerequisites:

Step1: Install Docker :


http://unixadvice.blogspot.com/2017/06/


Step 2: Install Kubernetes :


http://unixadvice.blogspot.com/2017_07_06_archive.html


Step 3: Starting Minikube :



http://unixadvice.blogspot.com/2017_07_08_archive.html


Step 4:
Deploying your "microservice" made with Node.js


Install Node.js on your server


wget http://nodejs.org/dist/v0.10.30/node-v0.10.30.tar.gz
Extract the archive and move into the new directory by typing:
tar xzvf node-v* && cd node-v*
There are a few packages that we need to download from the CentOS repositories in order to compile the code. Use yum to get these now:
sudo yum install gcc gcc-c++
Now, we can configure and compile the software:
./configure
make
The compilation will take quite awhile (almost 40 Minutes). When it is finished, you can install the software onto your system by typing:
sudo make install
To check that the installation was successful, you can ask Node to display its version number:
node --version
v0.10.30

[root@localhost node-v0.10.30]# node server.js
Received request for URL: /
Received request for URL: /favicon.ico

Go to this below link and you should be able to see : "Hello World"

http://localhost:8080/.

oot@localhost node-v0.10.30]# 
[root@localhost node-v0.10.30]# vi Dockerfile
[root@localhost node-v0.10.30]# eval $(minikube docker-env)
[root@localhost node-v0.10.30]# docker build -t hello-node:v1 .
Sending build context to Docker daemon  139.8MB
Step 1 : FROM node:6.9.2
6.9.2: Pulling from library/node
75a822cd7888: Extracting [================================>                  ]  33.03MB/51.36MB
57de64c72267: Download complete 
75a822cd7888: Extracting [================================>                  ]  33.55MB/51.36MBding [===============================================75a822cd7888: Extracting [=================================>                 ]  34.08MB/51.36MBB complete 

871436ab7225: Downloading [=========

871436ab7225: Downloading [===============================================>   ]  124.4MB/129.8MB
75a822cd7888: Pull complete 
57de64c72267: Pull complete 
4306be1e8943: Pull complete 
871436ab7225: Pull complete 
0110c26a367a: Pull complete 
1f04fe713f1b: Pull complete 
ac7c0b5fb553: Pull complete 
Digest: sha256:2e95be60faf429d6c97d928c762cb36f1940f4456ce4bd33fbdc34de94a5e043                                   
Status: Downloaded newer image for node:6.9.2
 ---> faaadb4aaf9b
Step 2 : EXPOSE 8080
 ---> Running in 2344d4a2b96b
 ---> 66fd396faf13
Removing intermediate container 2344d4a2b96b
Step 3 : COPY server.js .
 ---> 5d02c444af18
Removing intermediate container 90dd85314e64
Step 4 : CMD node server.js
 ---> Running in 2db4341976b8
 ---> 801fe2cdebe3
Removing intermediate container 2db4341976b8
Successfully built 801fe2cdebe3

[root@localhost node-v0.10.30]# 

[root@localhost node-v0.10.30]# kubectl get deployments
NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hello-minikube        1         1         1            0           2d
hello-minikube2       1         1         1            1           2d
kubernetes-bootcamp   1         1         1            0           2d
mysql-minikube        1         1         1            0           12h
You have new mail in /var/spool/mail/root
[root@localhost node-v0.10.30]# kubectl run hello-node --image=hello-node:v1 --port=8080
deployment "hello-node" created

[root@localhost node-v0.10.30]# 
[root@localhost node-v0.10.30]# kubectl get deployments
NAME                  DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hello-minikube        1         1         1            0           2d
hello-minikube2       1         1         1            1           2d
hello-node            1         1         1            1           58s
kubernetes-bootcamp   1         1         1            0           2d
mysql-minikube        1         1         1            0           12h
[root@localhost node-v0.10.30]# 

[root@localhost node-v0.10.30]# kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /root/.minikube/ca.crt
    server: https://192.168.42.188:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /root/.minikube/apiserver.crt
    client-key: /root/.minikube/apiserver.key
[root@localhost node-v0.10.30


[root@localhost node-v0.10.30]# kubectl expose deployment hello-node --type=LoadBalancer
service "hello-node" exposed
[root@localhost node-v0.10.30]# 

[root@localhost node-v0.10.30]# kubectl get services
NAME              CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
hello-minikube    10.0.0.103         8080:30904/TCP   2d
hello-minikube2   10.0.0.19           8080:30451/TCP   2d
hello-node        10.0.0.8         8080:30026/TCP   52s
kubernetes        10.0.0.1            443/TCP          2d
[root@localhost node-v0.10.30]# kubectl get services
NAME              CLUSTER-IP   EXTERNAL-IP   PORT(S)          AGE
hello-minikube    10.0.0.103         8080:30904/TCP   2d
hello-minikube2   10.0.0.19           8080:30451/TCP   2d
hello-node        10.0.0.8         8080:30026/TCP   1m
kubernetes        10.0.0.1            443/TCP          2d
[root@localhost node-v0.10.30]# minikube service hello-node
Opening kubernetes service default/hello-node in default browser...
START /bin/firefox "http://192.168.42.188:30026"

this above command will automatically launch the browser with the hello world program.














Installing Ingress Controller - Kubernetes

Installing the Ingress Controller Prerequisites Make sure you have access to the Ingress controller image: For NGINX Ingress controll...