I was trying to deploy a Node.js application to the openshift as in this link here
I understand this code
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('Hello Http');
});
server.listen(3000);
and there is no issue running it locally
$ node server.js // saved as server.js
However, how does this work when I commit this application in openshift? This is very simple code. I have some downloaded code that is a chat application and client-server need to configure to listen on some port (I was using port number 3000 in my localhost).
It works on port number 3000 in localhost but how can I make it to work in Openshift?
What Is a Deployment? OpenShift Container Platform deployments provide fine-grained management over common user applications. They are described using three separate API objects: A deployment configuration, which describes the desired state of a particular component of the application as a pod template.
About nodes. A node is a virtual or bare-metal machine in a Kubernetes cluster. Worker nodes host your application containers, grouped as pods. The control plane nodes run services that are required to control the Kubernetes cluster.
Red Hat OpenShift is a leading enterprise Kubernetes platform1 that enables a cloud-like experience everywhere it's deployed. Whether it's in the cloud, on-premise or at the edge, Red Hat OpenShift gives you the ability to choose where you build, deploy, and run applications through a consistent experience.
You need to listen on port process.env.OPENSHIFT_NODEJS_PORT
. So something like this should work:
server.listen(process.env.OPENSHIFT_NODEJS_PORT || 3000);
See here for example: Error: listen EACCES on Openshift app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With