OKD-runner
This library helps to write self-deploying Node.js applications for OpenShift and soon in Kubernetes.
Setup
Now this guide assume you got an OpenShift cluster up and running, if you don't, you still can get access to OpenShift Online for free or setup one in your computer via Minishift or oc cluster-up.
Once you have OpenShift sorted out, you'll need to create a project/namespace manually, you can do this by login into the console and clicking into new project, thats the only limitation of the module at the moment of not being able to create it for you.
Getting Started
Before continue you'll need an OpenShift cluster up and running, the easiest way is to subscribe here OpenShift Online for free or if you feel strong you can setup one in your computer via Minishift or oc cluster-up.
Once you have OpenShift sorted out, you'll need to create a project/namespace manually, you can do this by login into the web console and clicking into new project.
Self Deploying
Now we should get back to our working directory and install okd-runner
module from npm, this is the module that does the magic:
npm install install okd-runner --save
We add the module:
let count = 0 const run = // <- self-deploy module
By adding this module you still can run your application locally, the only difference is that now you can choose a different execution runtime by passing the --cloud
flag, this flag will tell your JS program to run in OpenShift:
node app --cloud # or node app -c for short
- The first time it will ask you for your cluster credentials:
- And also to choose the namespace/project:
Runtime
After that your application will start the deployment:
...building okURL: http://my-app-dev-01.7e14.starter-us-west-2.openshiftapps.com......npm info using node@v10.14.0npm info lifecycle my-app@1.0.0~prestart: my-app@1.0.0npm info lifecycle my-app@1.0.0~start: my-app@1.0.0 > my-app@1.0.0 start /opt/app-root/src> node app.js response: 1550511176623...
Here you can see the logs of you container plus the URL, to exit you just need to press Ctrl-C
and you will get back to your console.
Updating
From now everything is similar as to run your application locally, let's add a line of code to get the pods name, this way showcase how we can make an update:
let count = 0const run = console
We run our application again:
node app --cloud
This time it goes straight to deployment.
Cleaning up
To remove your application you just need to pass the -rm
flag:
node app -rm
You see not a single YAML file, hope this module helps you simplify your workflow while developing Node.JS micro-services. Also this module is still under development so feel free to contribute by sending suggestions, pull request, improvements or by opening an issue.