From c3d600a0417b68fede7bef5a33b43cac04d3b1e4 Mon Sep 17 00:00:00 2001 From: brennv Date: Mon, 4 Apr 2016 13:17:54 -0700 Subject: [PATCH 1/4] Added install notes --- README.md | 82 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 29516e0..9f6c5ff 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,32 @@ Node.js sample app on OpenShift! ----------------- -This example will serve a welcome page and the current hit count as stored in a database to [http://host:8080](http://host:8080). +This example will serve a welcome page and the current hit count as stored in a database. -### OpenShift setup ### +### OpenShift v3 setup -One option is to use the Docker all-in-one launch as described in the [OpenShift Origin project](https://github.com/openshift/origin). +There are four methods to get started with OpenShift v3: running a virtual machine with Vagrant, starting a Docker continer, downloading the binary, or running an Ansible playbook. -### The project ### +Vagrant into a Virtual Machine -After logging in with `oc login`, if you don't have a project setup all ready, go ahead and take care of that +One option is to use the Vagrant all-in-one launch as described in the [OpenShift Origin All-In-One Virtual Machine](https://www.openshift.org/vm/). This option works on Mac, Windows and Linux, but requires that you install [Vagrant](https://www.vagrantup.com/downloads.html) running [VirtualBox](https://www.virtualbox.org/wiki/Downloads). + +Running a Docker Container + +Another option is running the OpenShift Origin Docker container image from [Docker Hub](https://hub.docker.com/r/openshift/origin/) launch as described in the [Getting Started for Administrators](https://docs.openshift.org/latest/getting_started/administrators.html#running-in-a-docker-container). This method is supported on Fedora, CentOS, and Red Hat Enterprise Linux (RHEL) hosts only. + +Downloading the Binary + +Red Hat periodically publishes OpenShift Origin Server binaries for Linux, which you can download on the OpenShift Origin GitHub [Release](https://github.com/openshift/origin/releases) page. Instructions on how to install and launch the Openshift Origin Server from binary are described in [Getting Started for Administrators](https://docs.openshift.org/latest/getting_started/administrators.html#downloading-the-binary). + +Running Ansible + +Outlined as the [Advanced Intallation](https://docs.openshift.org/latest/install_config/install/advanced_install.html) method for poduction environments, OpenShift Origin is also installable via Ansible playbook made avaialble on the GitHub [openShift-ansible](https://github.com/openshift/openshift-ansible) repo. + + +### The project + +After logging in with `oc login` (default username/password: openshift), if you don't have a project setup all ready, go ahead and take care of that $ oc new-project nodejs-echo --display-name="nodejs" --description="Sample Node.js app" @@ -17,60 +34,79 @@ That's it, project has been created. Though it would probably be good to set yo $ oc project nodejs-echo -### The app ### +### The app Now let's pull in the app source code from [GitHub repo](https://github.com/openshift/nodejs-ex) (fork if you like). -#### create #### +#### create $ oc new-app https://github.com/openshift/nodejs-ex -l name=myapp That should be it, this form of `new-app` will locate an appropriate image on DockerHub, create an ImageStream for that image, and then create the right build configuration, deployment configuration and service definition. Next you'll be able to kick off the build, though new-app will kick off a build once all required dependencies are confirmed. The -l flag will apply a label of "name=myapp" to all the resources created by new-app, for easy management later. -Note, you can follow along with the web console (located at https://ip-address:8443/console) to see what new resources have been created and watch the progress of the build and deployment. +Check the status of your new nodejs app with the command: -#### build #### + $ oc status + +Which should return something like: -If the build is not started (you can check by running "oc get builds"), start one and stream the logs with: + $ In project nodejs (nodejs-echo) on server https://10.2.2.2:8443 + +Note the address, as yours may differ. This is the address for the web GUI console. You can follow along with the web console to see what new resources have been created and watch the progress of the build and deployment. + +#### build + +If the build is not yet started (you can check by running `oc get builds`), start one and stream the logs with: $ oc start-build nodejs-ex --follow -You can alternatively leave off `--follow` and use `oc build-logs nodejs-ex-n` where n is the number of the build to track the output of the build. +You can alternatively leave off `--follow` and use `oc build-logs nodejs-ex-n` where *n* is the number of the build to track the output of the build. -#### deploy #### +#### deploy Deployment happens automatically once the new application image is available. To monitor its status either watch the web console or execute `oc get pods` to see when the pod is up. Another helpful command is - $ oc status + $ oc get svc -This will help indicate what IP address the service is running, the default port for it to deploy at is 8080. +This will help indicate what IP address the service is running, the default port for it to deploy at is 8080. Output should look like: -#### enjoy #### + $ NAME CLUSTER-IP EXTERNAL-IP PORT(S) SELECTOR AGE + $ nodejs-ex 172.30.249.251 8080/TCP deploymentconfig=nodejs-ex,name=myapp 17m + +#### route -Determine the service ip for the application by running +An OpenShift route exposes a service at a host name, like www.example.com, so that external clients can reach it by name. - $ oc get svc +DNS resolution for a host name is handled separately from routing; your administrator may have configured a cloud domain that will always correctly resolve to the OpenShift router, or if using an unrelated host name you may need to modify its DNS records independently to resolve to the router. -Run/test your app by browsing to +As of OpenShift v3.1 routes can be configured in the web console or via CLI. Using the CLI, you can expose a route as follows: - $ curl service-ip-address:8080 + $ oc expose service/ --hostname= + +If you're running OpenShift on a local machine, you can preview the new app by setting a local route like: -#### update #### + $ oc expose service/nodejs-ex --hostname=10.2.2.2 + +#### enjoy + +This example will serve a welcome page and the current hit count as stored in a database to [http://10.2.2.2](http://10.2.2.2). + +#### update Assuming you used the URL of your own forked report, we can easily push changes to that hosted repo and simply repeat the steps above to build which will trigger the new built image to be deployed. -#### delete #### +#### delete $ oc delete all -l name=myapp To remove all the resources with the label "name=myapp". -###Debugging Unexpected Failures +### Debugging Unexpected Failures Review some of the common tips and suggestions [here](https://github.com/openshift/origin/blob/master/docs/debugging-openshift.md). -### Web UI ### +### Web UI To run this example from the Web UI, you can same steps following done on the CLI as defined above by [The project](#the-project). Here's a video showing it in motion: From 53a510899aa171c2f898c1424673e3bdb9986b39 Mon Sep 17 00:00:00 2001 From: brennv Date: Mon, 4 Apr 2016 14:46:02 -0700 Subject: [PATCH 2/4] Adding mongodb service (Hmmm, now restart everything and it automagically works? Or add the mongodb url to the nodejs pod some how?) --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 9f6c5ff..927b304 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,16 @@ As of OpenShift v3.1 routes can be configured in the web console or via CLI. Usi If you're running OpenShift on a local machine, you can preview the new app by setting a local route like: $ oc expose service/nodejs-ex --hostname=10.2.2.2 + +#### database + +You may have noticed the "Page view count" reads "No database configured". Let's fix that by adding a MongoDB pod: + + $ oc new-app -e \ + $ MONGODB_USER=admin,MONGODB_DATABASE=mongo_db,MONGODB_PASSWORD=secret,MONGODB_ADMIN_PASSWORD=super-secret \ + $ centos/mongodb-26-centos7 + +(Database work to be continued...) #### enjoy From d9c8c2e5e0e9f433f2ccfec5b2a4e103004a94b0 Mon Sep 17 00:00:00 2001 From: brennv Date: Mon, 4 Apr 2016 14:49:43 -0700 Subject: [PATCH 3/4] Formatting --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 927b304..647e507 100644 --- a/README.md +++ b/README.md @@ -7,19 +7,19 @@ This example will serve a welcome page and the current hit count as stored in a There are four methods to get started with OpenShift v3: running a virtual machine with Vagrant, starting a Docker continer, downloading the binary, or running an Ansible playbook. -Vagrant into a Virtual Machine +#### Vagrant into a Virtual Machine One option is to use the Vagrant all-in-one launch as described in the [OpenShift Origin All-In-One Virtual Machine](https://www.openshift.org/vm/). This option works on Mac, Windows and Linux, but requires that you install [Vagrant](https://www.vagrantup.com/downloads.html) running [VirtualBox](https://www.virtualbox.org/wiki/Downloads). -Running a Docker Container +#### Run a Docker Container Another option is running the OpenShift Origin Docker container image from [Docker Hub](https://hub.docker.com/r/openshift/origin/) launch as described in the [Getting Started for Administrators](https://docs.openshift.org/latest/getting_started/administrators.html#running-in-a-docker-container). This method is supported on Fedora, CentOS, and Red Hat Enterprise Linux (RHEL) hosts only. -Downloading the Binary +#### Download the Binary Red Hat periodically publishes OpenShift Origin Server binaries for Linux, which you can download on the OpenShift Origin GitHub [Release](https://github.com/openshift/origin/releases) page. Instructions on how to install and launch the Openshift Origin Server from binary are described in [Getting Started for Administrators](https://docs.openshift.org/latest/getting_started/administrators.html#downloading-the-binary). -Running Ansible +#### Run Ansible Outlined as the [Advanced Intallation](https://docs.openshift.org/latest/install_config/install/advanced_install.html) method for poduction environments, OpenShift Origin is also installable via Ansible playbook made avaialble on the GitHub [openShift-ansible](https://github.com/openshift/openshift-ansible) repo. From dd22958804f2913b588e13e8d397ffea401ca246 Mon Sep 17 00:00:00 2001 From: brennv Date: Mon, 4 Apr 2016 16:01:48 -0700 Subject: [PATCH 4/4] Testing mongoldb config --- openshift/templates/nodejs.json | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/openshift/templates/nodejs.json b/openshift/templates/nodejs.json index 82df67c..61eda27 100644 --- a/openshift/templates/nodejs.json +++ b/openshift/templates/nodejs.json @@ -191,23 +191,27 @@ "env": [ { "name": "DATABASE_SERVICE_NAME", - "value": "${DATABASE_SERVICE_NAME}" + "value": "mongodb-26-centos7" }, { "name": "MONGODB_USER", - "value": "${MONGODB_USER}" + "value": "admin" }, { "name": "MONGODB_PASSWORD", - "value": "${MONGODB_PASSWORD}" + "value": "secret" }, { "name": "MONGODB_DATABASE", - "value": "${MONGODB_DATABASE}" + "value": "mongo_db" }, { "name": "MONGODB_ADMIN_PASSWORD", - "value": "${MONGODB_ADMIN_PASSWORD}" + "value": "super-secret" + }, + { + "name": "MONGODB_URL", + "value": "172.30.27.142:27017" } ], "resources": {