Chapter 9. Deploy an Application

In this reference architecture the cakephp application is used as a sample application. This sample application can be found at https://hub.openshift.com/quickstarts/73-cakephp. A list of example applications can be found at https://hub.openshift.com/quickstarts/all or in the OpenShift documentation at https://docs.openshift.com/container-platform/3.5/dev_guide/migrating_applications/quickstart_examples.html.

Access the pubic url endpoint of the OpenShift deployment at https://openshift-master.hpecloud.test:8443/console/command-line for instructions on setting up the command line interface. This link will display instructions on downloading and installing the oc commandline tools as shown in figure 33.

Command Line Tools

Figure 33: Command Line Tools

Using the oc login command, log into OpenShift using the public URL and the token available from the console command-line interface described above.

oc login https://openshift-master.hpecloud.test:8443 --token=zQN6GDIPOWpklX-Lq4DCCL2CMRRI5jdCYEYIjW5GofA

CakePHP Sample Application

Create a new Project

Use the oc new-project command to create a new OpenShift Container Platform project for the application.

$ oc new-project my-app
Now using project "my-app" on server "https://openshift-master.hpecloud.test: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.

Create a new Application

Create a new application by executing the oc new-app command and specifying the git repository for the cakephp application.

$ oc new-app https://github.com/openshift/cakephp-ex.git --name=cakephp
--> Found image 79f7d44 (3 weeks old) in image stream "openshift/php" under tag "7.0" for "php"
    Apache 2.4 with PHP 7.0
    -----------------------
    Platform for building and running PHP 7.0 applications
    Tags: builder, php, php70, rh-php70
    * The source repository appears to match: php
    * A source build using source code from https://github.com/openshift/cakephp-ex.git will be created
      * The resulting image will be pushed to image stream "cakephp:latest"
      * Use 'start-build' to trigger a new build
    * This image will be deployed in deployment config "cakephp"
    * Port 8080/tcp will be load balanced by service "cakephp"
      * Other containers can access this service through the hostname "cakephp"
--> Creating resources ...
    imagestream "cakephp" created
    buildconfig "cakephp" created
    deploymentconfig "cakephp" created
    service "cakephp" created
--> Success
    Build scheduled, use 'oc logs -f bc/cakephp' to track its progress.
    Run 'oc status' to view your app.

Expose the Application

Create a route to expose the application using the subdomain that was created during the OpenShift Container Platform deployment and the oc expose command. In our example the subdomain specified was paas.hpecloud.test .

$ oc expose svc cakephp

Access the Application

The cakephp application can now be accessed via a browser, in our example the URL for the cakephp application is http://cakephp-my-app.paas.hpecloud.test/.

Cake Sample Application

Figure 34: Cake Sample Application