Bootstrap FreeKB - OpenShift - Deploy an application from an image
OpenShift - Deploy an application from an image

Updated:   |  OpenShift articles

An image contains the code used to create a deployment. Then, a deployment can be created from an image, which should then create a replica set (which is the number of pods that should be created), and then the pods should be created.

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

The oc new-app command is used to deploy an application.

There are various ways to deploy an app.


From an image

The oc get images command can be used to determine if the image has already been pulled down. Something like this should be returned. In this example, there are 4 php images (versions 5.5, 5.6, 7.0 and 7.1).

~]# oc get images
NAME                                                                      IMAGE REFERENCE


The following command would deploy the php application from the latest image (version 7.1).

oc new-app php


Or, you could specify the exact image you want to deploy.

oc new-app


The --as-deployment-config flag can be used to create the deployment as a deployment config instead of a regular "deployment".

oc new-app --as-deployment-config


In this example, there was no image for the hello-world application, thus a call was made to Docker Hub for the image, which is like deploying the image from Docker Hub.

~]$ oc new-app hello-world
warning: Cannot find git. Ensure that it is installed and in your path. Git is required to work with git repositories.
--> Found container image feb5d9f (8 months old) from Docker Hub for "hello-world"

    * An image stream tag will be created as "hello-world:latest" that will track this image

--> Creating resources ... "hello-world" created
    deployment.apps "hello-world" created
--> Success
    Run 'oc status' to view your app.


On the other hand, if the image exists, something like this should be displayed.

--> Found image 28c6ff6 (16 months old) in image stream "openshift/php" under tag "7.1" for "php"

    Apache 2.4 with PHP 7.1
    PHP 7.1 . . .

    Tags: builder, php, php71, rh-php71

    * This image will be deployed in deployment config "php"
    * Ports 8080/tcp, 8443/tcp will be load balanced by service "php"
      * Other containers can access this service through the hostname "php"

--> Creating resources ... "php:7.1" created "php" created
    service "php" created
--> Success
    Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
     'oc expose svc/php' 
    Run 'oc status' to view your app.


If the --as-deployment-config flag was not used, the oc get deployments command can be used to list the deployments. 

~]$ oc get deployments
php       1/1     1            1           38s


On the other hand, if the --as-deployment-config flag is used, the oc get deploymentconfigs command can be used to list the deployment configs.

~]$ oc get deploymentconfigs
my-app    1          1         1         config,image(my-app:latest)


If the --as-deployment-config flag was used, the oc rollout history command can be used to see that the latet image was rolled out. In this example, revision 1 is the original deployment.

~]# oc rollout history deploymentconfig/my-app
1           Complete    config change


The oc get pods can be used to determine if the pod was spun up from the deployment.

~]$ oc get pods
NAME                   READY   STATUS    RESTARTS   AGE
php-68dd9b68f4-r97m9   1/1     Running   0          109s


The oc get imagestreams command can be used to display the image stream.

~]# oc get imagestreams
NAME      DOCKER REPO                                TAGS      UPDATED
php       docker-registry.default.svc:5000/foo/php   7.1 


And the oc describe is php command can display a bit more information.

~]# oc describe is php
Name:                   php
Namespace:              foo
Created:                13 minutes ago
Labels:                 <none>
Docker Pull Spec:       docker-registry.default.svc:5000/foo/php
Image Lookup:           local=false
Unique Images:          0
Tags:                   1


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

Please enter 512e8e in the box below so that we can be sure you are a human.