I have an node.js application called "process-core" which has the main logic to run another node.js app called "page-core".Through "Process-core" I am deploying the distribution folder(static contents) of the "page-core" application.I am deploying this using kubernetes.
dockerfile used to build image for "process-core"
FROM node:8
RUN mkdir -p usr/src/app
WORKDIR /usr/src/app
COPY . .
WORKDIR /usr/src/app
RUN npm install
CMD [ "npm","start" ]
my server.js goes like this-
var express = require('express');
var cors = require('cors')
var app = express();
var path = require('path');
var router = express.Router();
var request = require('request');
var api = require('./server/api.js')
const base_url = 'http://localhost:8080/api/';
const static_dir = '/home/vignesh/page-core-devbranch/dist'; // location of
const assets_dir = path.join(__dirname + '/server/assets/'); dist folder
const tools_dir = path.join(__dirname + '/server/tools/');
const index_file = path.join(static_dir + '/index.html');
/* static */
app.use(cors())
app.use(express.static(static_dir));
app.use('/assets', express.static(assets_dir));
app.use('/tools', express.static(tools_dir));
/* listen */
app.listen(5000);
node.yaml
apiVersion: v1
kind: Service
metadata:
labels:
node: test
name: nodetest
spec:
ports:
- nodePort: 30000
port: 5000
protocol: TCP
targetPort: 5000
selector:
node: test
type: NodePort
---
apiVersion: v1
kind: Pod
metadata:
name: nodetest
labels:
node: test
spec:
containers:
- name: node-test
image: suji165475/devops-sample:processcore
ports:
- containerPort: 5000
When I hit http://206.189.22.155:30000/ i get an error saying Cannot GET /
FROM node:8
RUN mkdir -p usr/src/app
WORKDIR /usr/src/app
COPY . .
WORKDIR /usr/src/app
RUN npm install
EXPOSE 5000
CMD [ "npm","start" ]
You have not expose port from docker image in docker file please add one line as EXPOSE 5000
to open the container port 5000 from docker container.