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
- 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
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
Track the build log until the app is built and deployed.
~]$ oc logs -f bc/nodejs-ex
Expose a route to the service.
~]$ oc expose svc/nodejs-ex
Access the application.
~]$ minishift openshift service nodejs-ex -n myproject
To stop Minishift, use the following command:
~]$ minishift stop Stopping local OpenShift cluster... Stopping "minishift"...
For more information about creating applications in OpenShift, see Creating New Applications in the OpenShift documentation.
4.3. WildFly Application Deployment
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.
~]$ oc login https://192.168.42.189:8443 --username="developer" --password="developer" Login successful. You have access to the following projects and can switch between them with 'oc project <projectname>': * myproject Using project "myproject".
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>
.~]$ oc new-app proj-00 --display-name="Project 00 - initial" Now using project "project-00" on server "https://192.168.42.189:8443". You can add applications to this project with the 'new-app' command. For example, try: oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-ex.git to build a new example application in Ruby.
To verify that the correct project name was selected:
~]$ oc projects You have access to the following projects and can switch between them with 'oc project <projectname>': myproject - My Project * project-00 - Project 00 - initial Using project "project-00" on server "https://192.168.42.189:8443".
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 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 35657 100 35657 0 0 79033 0 --:--:-- --:--:-- --:--:-- 78887
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 imagestream "wildfly" created
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:
~]$ oc get is -n openshift NAME DOCKER REPO TAGS UPDATED jenkins 172.30.1.1:5000/openshift/jenkins latest,1,2 36 hours ago mariadb 172.30.1.1:5000/openshift/mariadb latest,10.1 36 hours ago mongodb 172.30.1.1:5000/openshift/mongodb latest,3.2,2.6 + 1 more... 36 hours ago mysql 172.30.1.1:5000/openshift/mysql 5.5,latest,5.7 + 1 more... 36 hours ago nodejs 172.30.1.1:5000/openshift/nodejs 0.10,4,latest 36 hours ago perl 172.30.1.1:5000/openshift/perl 5.20,5.16,latest + 1 more... 36 hours ago php 172.30.1.1:5000/openshift/php 5.6,5.5,latest + 1 more... 36 hours ago postgresql 172.30.1.1:5000/openshift/postgresql latest,9.5,9.4 + 1 more... 36 hours ago python 172.30.1.1:5000/openshift/python 3.3,2.7,latest + 2 more... 36 hours ago redis 172.30.1.1:5000/openshift/redis latest,3.2 36 hours ago ruby 172.30.1.1:5000/openshift/ruby 2.0,latest,2.3 + 1 more... 36 hours ago wildfly 172.30.1.1:5000/openshift/wildfly latest,10.1,10.0 + 2 more... 2 hours ago
Create the application in OpenShift
~]$ oc new-app --name=myapp wildfly:latest~https://github.com/Preeticp/os-sample-java-web --> Found image 24b6639 (2 weeks old) in image stream "openshift/wildfly" under tag "latest" for "wildfly:latest" WildFly 10.1.0.Final -------------------- Platform for building and running JEE applications on WildFly 10.1.0.Final Tags: builder, wildfly, wildfly10 * A source build using source code from https://github.com/Preeticp/os-sample-java-web will be created * The resulting image will be pushed to image stream "myapp:latest" * Use 'start-build' to trigger a new build * This image will be deployed in deployment config "myapp" * Port 8080/tcp will be load balanced by service "myapp" * Other containers can access this service through the hostname "myapp" --> Creating resources ... imagestream "myapp" created buildconfig "myapp" created deploymentconfig "myapp" created service "myapp" created --> Success Build scheduled, use 'oc logs -f bc/myapp' to track its progress. Run 'oc status' to view your app.
Monitor the application deployment by checking the output of
oc status
:~]$ oc status -v In project Project 00 - initial (project-00) on server https://192.168.42.189:8443 svc/myapp - 172.30.38.38:8080 dc/myapp deploys istag/myapp:latest <- bc/myapp source builds https://github.com/Preeticp/os-sample-java-web on openshift/wildfly:latest deployment #1 deployed about a minute ago - 1 pod Info: * pod/myapp-1-build has no liveness probe to verify pods are still running. try: oc set probe pod/myapp-1-build --liveness ... * dc/myapp has no readiness probe to verify pods are ready to accept traffic or ensure deployment is successful. try: oc set probe dc/myapp --readiness ... * dc/myapp has no liveness probe to verify pods are still running. try: oc set probe dc/myapp --liveness ... View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.
You can examine a detailed very of the application being deployed:
~]$ oc describe svc/myapp Name: myapp Namespace: project-00 Labels: app=myapp Selector: app=myapp,deploymentconfig=myapp Type: ClusterIP IP: 172.30.38.38 Port: 8080-tcp 8080/TCP Endpoints: 172.17.0.3:8080 Session Affinity: None No events.
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 route "myapp" exposed
Run the
oc status
command again to verify that the application is correctly deployed:~]$ oc status In project Project 00 - initial (project-00) on server https://192.168.42.189:8443 http://myapp-project-00.192.168.42.189.nip.io to pod port 8080-tcp (svc/myapp) dc/myapp deploys istag/myapp:latest <- bc/myapp source builds https://github.com/Preeticp/os-sample-java-web on openshift/wildfly:latest deployment #1 deployed 8 hours ago - 1 pod View details with 'oc describe <resource>/<name>' or list everything with 'oc get all'.
-
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.