Chapter 4. Deploying an Application
Deploying an application through minishift requires a few steps. Those steps are covered here first as a simplified version of the process using a Node.js
example, then a sample WildFly
deployment. The section Section 9.3, “Deploying an Application with Docker” explains application deployment with Docker.
4.1. Prerequisites to Deploying an Application Copy linkLink copied to clipboard!
- Your code needs to already be on the Internet, so upload it and make any pull requests so that it is available in a reachable repository. These examples use sample applications hosted on github.
-
You have already installed minishift, and have run
minishift start
.
4.2. Simplified Explanation of Application Deployment Copy linkLink copied to clipboard!
OpenShift provides various sample applications, such as templates, builder applications, and quickstarts. The following steps describe how to deploy a sample Node.js application from the command-line.
Create a Node.js example 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
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Track the build log until the app is built and deployed.
oc logs -f bc/nodejs-ex
~]$ oc logs -f bc/nodejs-ex
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Expose a route to the service.
oc expose svc/nodejs-ex
~]$ oc expose svc/nodejs-ex
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Access the application.
minishift openshift service nodejs-ex -n myproject
~]$ minishift openshift service nodejs-ex -n myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To stop Minishift, use the following command:
minishift stop
~]$ minishift stop Stopping local OpenShift cluster... Stopping "minishift"...
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
For more information about creating applications in OpenShift, see Creating New Applications in the OpenShift documentation.
4.3. WildFly Application Deployment Copy linkLink copied to clipboard!
This step may not be needed if you just ran minishift start
. Starting minishift automatically logs you in as the developer user.
Deploying a WildFly application requires a few steps, so here’s an example of deploying a new app:
If you haven’t already, login to your OpenShift account. This example uses the developer account in the OpenShift cluster, but you can login as any other valid user.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can use reuse an existing OpenShift project, or you can create a new project. You create a project with
oc new-app <project_name>
.Copy to Clipboard Copied! Toggle word wrap Toggle overflow To verify that the correct project name was selected:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Download a copy of the
.json
file for the WildFly app. This should create a filewildfly.json
:curl -o wildfly.json https://raw.githubusercontent.com/projectatomic/adb-utils/master/services/openshift/templates/adb/image-streams-centos7.json
~]$ curl -o wildfly.json https://raw.githubusercontent.com/projectatomic/adb-utils/master/services/openshift/templates/adb/image-streams-centos7.json % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 35657 100 35657 0 0 79033 0 --:--:-- --:--:-- --:--:-- 78887
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create an image stream for the WildFly application. An image stream is simply a set of docker container images, condensed into an image stream to assist deployment. An image stream for wildfly will help us in this example:
oc create -f wildfly.json -n openshift
~]$ oc create -f wildfly.json -n openshift imagestream "wildfly" created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check the available image streams and verify that the WildFly image stream was created successfully. In this example, it’s the last image stream in the list:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the application in OpenShift
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Monitor the application deployment by checking the output of
oc status
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can examine a detailed very of the application being deployed:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Route service to the application. OpenShift starts a new internal service for each application was created with
oc newapp
, as shown above in the section Section 4.3, “WildFly Application Deployment”. Communication with the applications happens with a map to an external domain name with a feature called routes. Routes are setup by exposing an application:oc expose svc myapp
$ oc expose svc myapp route "myapp" exposed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the
oc status
command again to verify that the application is correctly deployed:Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Finally, check out the running application. The information on the third line of
oc status
output states the URI where users will access the running application, in this instancehttp://myapp-project-00.192.168.42.189.nip.io
Your address may vary from this, because OpenShift uses a different IP address for each exposed service.