Added database instructions

This commit is contained in:
brennv 2016-04-04 21:10:23 -07:00
parent 1fe477db29
commit 8a6c05bbc7

View file

@ -5,40 +5,46 @@ This example will serve a welcome page and the current hit count as stored in a
### OpenShift v3 setup ### OpenShift v3 setup
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. There are four methods to get started with OpenShift v3:
#### Vagrant into a Virtual Machine - Running a virtual machine with Vagrant
- Starting a Docker container
- Downloading the binary
- Running an Ansible playbook
#### Running a virtual machine with Vagrant
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). 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).
#### Run a Docker Container #### Starting 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. 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.
#### Download the Binary #### 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). 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).
#### Run Ansible #### Running an Ansible playbook
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. 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 ### Creating a 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 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" $ oc new-project nodejs-echo \
$ --display-name="nodejs" --description="Sample Node.js app"
That's it, project has been created. Though it would probably be good to set your current project to this (thought new-project does it automatically as well), such as: That's it, project has been created. Though it would probably be good to set your current project to this (thought new-project does it automatically as well), such as:
$ oc project nodejs-echo $ oc project nodejs-echo
### The app ### Configuring the web app
Now let's pull in the app source code from [GitHub repo](https://github.com/openshift/nodejs-ex) (fork if you like). Now let's pull in the app source code from [GitHub repo](https://github.com/openshift/nodejs-ex) (fork if you like).
#### create #### Create a new app
$ oc new-app https://github.com/openshift/nodejs-ex -l name=myapp $ oc new-app https://github.com/openshift/nodejs-ex -l name=myapp
@ -50,11 +56,11 @@ Check the status of your new nodejs app with the command:
Which should return something like: Which should return something like:
$ In project nodejs (nodejs-echo) on server https://10.2.2.2:8443 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. 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 #### Build the app
If the build is not yet started (you can check by running `oc get builds`), start one and stream the logs with: If the build is not yet started (you can check by running `oc get builds`), start one and stream the logs with:
@ -62,7 +68,7 @@ If the build is not yet started (you can check by running `oc get builds`), star
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 the app
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 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
@ -70,10 +76,10 @@ Deployment happens automatically once the new application image is available. T
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: 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:
$ NAME CLUSTER-IP EXTERNAL-IP PORT(S) SELECTOR AGE NAME CLUSTER-IP EXTERNAL-IP PORT(S) SELECTOR AGE
$ nodejs-ex 172.30.249.251 <none> 8080/TCP deploymentconfig=nodejs-ex,name=myapp 17m nodejs-ex 172.30.249.251 <none> 8080/TCP deploymentconfig=nodejs-ex,name=myapp 17m
#### route #### Configure routing
An OpenShift route exposes a service at a host name, like www.example.com, so that external clients can reach it by name. An OpenShift route exposes a service at a host name, like www.example.com, so that external clients can reach it by name.
@ -87,35 +93,48 @@ If you're running OpenShift on a local machine, you can preview the new app by s
$ oc expose service/nodejs-ex --hostname=10.2.2.2 $ oc expose service/nodejs-ex --hostname=10.2.2.2
#### database #### Create a database
You may have noticed the "Page view count" reads "No database configured". Let's fix that by adding a MongoDB pod: You may have noticed the home page "Page view count" reads "No database configured". Let's fix that by adding a MongoDB service:
$ oc new-app -e \ $ oc new-app centos/mongodb-26-centos7 \
$ MONGODB_USER=admin,MONGODB_DATABASE=mongo_db,MONGODB_PASSWORD=secret,MONGODB_ADMIN_PASSWORD=super-secret \ $ -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...) Running `oc status` will reveal the address of the newly created MongoDB database:
#### enjoy In project nodejs (nodejs-echo) on server https://10.2.2.2:8443
http://10.2.2.2 to pod port 8080-tcp (svc/nodejs-ex)
dc/nodejs-ex deploys istag/nodejs-ex:latest <-
bc/nodejs-ex builds https://github.com/openshift/nodejs-ex with openshift/nodejs:0.10
deployment #1 deployed 12 minutes ago - 1 pod
svc/mongodb-26-centos7 - 172.30.201.71:27017
dc/mongodb-26-centos7 deploys istag/mongodb-26-centos7:latest
deployment #1 deployed 2 minutes ago - 1 pod
Remove all the nodejs-ex resources with the label "name=myapp".
$ oc delete all -l name=myapp
Recreate the nodejs service again, but this time specifying the MONGO_URL environment variable:
$ oc new-app https://github.com/openshift/nodejs-ex -l name=myapp \
$ -e MONGO_URL=mongodb://admin:secret@172.30.201.71:27017/mongo_db
#### Success
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). 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 #### Pushing updates
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. 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 ### Debugging
$ oc delete all -l name=myapp
To remove all the resources with the label "name=myapp".
### Debugging Unexpected Failures
Review some of the common tips and suggestions [here](https://github.com/openshift/origin/blob/master/docs/debugging-openshift.md). 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: 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:
@ -123,4 +142,3 @@ To run this example from the Web UI, you can same steps following done on the CL
<a href="http://www.youtube.com/watch?feature=player_embedded&v=uocucZqg_0I&t=225" target="_blank"> <a href="http://www.youtube.com/watch?feature=player_embedded&v=uocucZqg_0I&t=225" target="_blank">
<img src="http://img.youtube.com/vi/uocucZqg_0I/0.jpg" <img src="http://img.youtube.com/vi/uocucZqg_0I/0.jpg"
alt="OpenShift 3: Node.js Sample" width="240" height="180" border="10" /></a> alt="OpenShift 3: Node.js Sample" width="240" height="180" border="10" /></a>