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 GitHub (https://github.com)
- From Docker Hub (https://hub.docker.com)
- From an image
- From a build
- From a JSON or YAML file (templates)
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
sha256:31e68b58657088d3f29c857aa257f9421ec58cb73cd225c2946cf327f0337366 registry.redhat.io/rhscl/php-70-rhel7@sha256:31e68b58657088d3f29c857aa257f9421ec58cb73cd225c2946cf327f0337366
sha256:920c2cf85b5da5d0701898f0ec9ee567473fa4b9af6f3ac5b2b3f863796bbd68 registry.redhat.io/rhscl/php-56-rhel7@sha256:920c2cf85b5da5d0701898f0ec9ee567473fa4b9af6f3ac5b2b3f863796bbd68
sha256:c82d399564d21b9737ac58c1c812c31c42b4afc94443a8e276cd63979dde2930 registry.redhat.io/openshift3/php-55-rhel7@sha256:c82d399564d21b9737ac58c1c812c31c42b4afc94443a8e276cd63979dde2930
sha256:e8d6446388de7a70b97d9883ab181858cfa13cb2b41ec216faef008caf6be615 registry.redhat.io/rhscl/php-71-rhel7@sha256:e8d6446388de7a70b97d9883ab181858cfa13cb2b41ec216faef008caf6be615
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 registry.example.com/openshift3/php-55-rhel7
The --as-deployment-config flag can be used to create the deployment as a deployment config instead of a regular "deployment".
oc new-app registry.example.com/openshift3/php-55-rhel7 --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 ...
imagestream.image.openshift.io "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 ...
imagestreamtag.image.openshift.io "php:7.1" created
deploymentconfig.apps.openshift.io "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
NAME READY UP-TO-DATE AVAILABLE AGE
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
NAME REVISION DESIRED CURRENT TRIGGERED BY
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
deploymentconfig.apps.openshift.io/my-app
REVISION STATUS CAUSE
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>
Annotations: openshift.io/image.dockerRepositoryCheck=2020-10-02T01:40:18Z
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