With the launch of the new OpenShift Online Next Gen Developer Preview, I thought I'd offer a few tips for NodeJS developers who are interested in giving the new Kubernetes-based platform a try.
This guide applies to the official OpenShift NodeJS S2I base images:
- OCP / OSO: RHEL NodeJS v0.10 Source2Image builder
- OpenShift Origin: CentOS NodeJS v0.10 Source2Image builder
To follow along, you'll need access to an OpenShift account, and a development environment with nodejs, git, and a copy of the "oc" command line tool.
Adapting your NodeJS source code to run on in a container can usually be accomplished in two easy steps:
- Include a package.json file with valid
"dependencies"
and"scripts"
sections - allowing builds to be started with "npm install", and webservers to be initialized via "npm start" - Your source repo should launch a single web process that listens on port "
8080
" in order to connect to the Kubernetes "Service" (or load-balancer)
Build and Deploy Images from the CLI
Schedule a new build and deployment, adding source code from "REPO_NAME" to a new image layer on top of "BASE_IMAGE":
oc new-app BASE_IMAGE~REPO_NAME
For example, to schedule a build and deployment, layering the pillar-base example repo on top of the system-provided nodejs base image, run:
oc new-app nodejs~http://github.com/OpenShiftDemos/pillar-base
The command output should look something like:
--> Found image 6f7f7d9 (5 weeks old) in image stream "nodejs" in project "openshift" under tag "0.10" for "nodejs"Node.js 0.10
------------
Platform for building and running Node.js 0.10 applicationsTags: builder, nodejs, nodejs010
* A source build using source code from http://github.com/OpenShiftDemos/pillar-base will be created
* The resulting image will be pushed to image stream "pillar-base:latest"
* This image will be deployed in deployment config "pillar-base"
* Port 8080/tcp will be load balanced by service "pillar-base"
* Other containers can access this service through the hostname "pillar-base"--> Creating resources with label app=pillar-base ...
imagestream "pillar-base" created
buildconfig "pillar-base" created
deploymentconfig "pillar-base" created
service "pillar-base" created
--> Success
Build scheduled, use 'oc logs -f bc/pillar-base' to track its progress.
Run 'oc status' to view your app
Several new kubernetes objects (service, deploymentconfig, imagestream, buildconfig) have been successfully created, as shown in the output.
To make your new Kubernetes service available via an http route, run the following command after updating it to include your service name as the last argument:
oc expose svc pillar-base
Then, run "oc status" to find the host address where your NodeJS app will be available.
Runtime configuration via Environment variables:
The container runtime environment can be configured by manipulating the following Env vars:
Name | Description | Default Value |
---|---|---|
NODE_ENV
|
NodeJS runtime mode
|
production
|
NPM_RUN
|
Select an alternate / custom runtime mode, defined in your
package.json file’s "scripts" section
Default init command:
npm run $NPM_RUN
|
start
|
DEV_MODE
|
When set to "true", nodemon will be used to automatically restart the server
When
DEV_MODE is enabled, the default value for
NODE_ENV will change to "development" (if not explicitly set), and the
NPM_RUN config option will have no effect
|
false
|
Alternate NodeJS Base Images
Additional NodeJS releases are available for Source2Image and Docker ONBUILD, making it easy to build application images that will run on OpenShift, Kubernetes, or any other platform that includes Docker image support.
Ready to give OpenShift a try?
Don't have access to an OpenShift / Kubernetes cluster? No problem! There are plenty of ways to get started:
- Sign up for the OpenShift Online 3 Developer Preview
- Fire up a local OpenShift Development VM using Vagrant and Virtualbox with "vagrant init thesteve0/openshift-origin & vagrant up"
- Try our new OpenShift-on-Docker environment with "oc cluster up"
- Build your own OpenShift cluster w/ Ansible: http://github.com/openshift/openshift-ansible
- Sign up for OpenShift Dedicated w/ ops and support from Red Hat
- Run your own OpenShift Container Platform w/ support from Red Hat
저자 소개
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.