
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.
There are various ways to deploy an app on OpenShift.
- From GitHub (https://github.com)
- From Docker Hub (https://hub.docker.com)
- From an image
- From a build
- From a template
- From a JSON or YAML file (templates)
The oc new-app or oc create command can be used to deploy an application from GitHub to OpenShift. If you are not familiar with the oc command, check out my article OpenShift - Getting Started with the oc command.
If git is not installed on your OpenShift server, the dnf install or yum install command can be used to install the git CLI.
dnf install git
Let's say you want to deploy the Python source to image (s2i) on OpenShift. In this scenario, https://github.com/sclorg/s2i-python-container is the URL for this repository. Let's first see if the repository can be cloned using the git clone command. So far, so good.
[john.doe@server1 ~]$ git clone https://github.com/sclorg/s2i-python-container.git
Cloning into 's2i-python-container'...
remote: Enumerating objects: 7255, done.
remote: Counting objects: 100% (1164/1164), done.
remote: Compressing objects: 100% (195/195), done.
remote: Total 7255 (delta 1001), reused 1045 (delta 951), pack-reused 6091 (from 1)
Receiving objects: 100% (7255/7255), 10.17 MiB | 28.31 MiB/s, done.
Resolving deltas: 100% (4431/4431), done.
On the other hand, if the git clone command hangs for a while and then eventually returns something like this with a reference to a proxy server, the git CLI may need to be configured to use a proxy server.
~]$ git clone https://github.com/sclorg/s2i-python-container
Cloning into 's2i-python-container'...
fatal: unable to access 'https://github.com/sclorg/s2i-python-container/': Failed to connect to proxy.example.com port 1080: Connection timed out
In this scenario, you could use the git config command to instruct git to use your proxy server.
git config --global http.proxy http://proxy.example.com:80
git config --global https.proxy https://proxy.example.com:443
And here is an example with username and password.
git config --global http.proxy http://username:password@proxy.example.com:80
git config --global https.proxy https://username:password@proxy.example.com:443
By the way, this will update the hidden .gitconfig file in your present working directory to have the proxy servers, something like this.
[http]
proxy = http://proxy.example.com:80
[https]
proxy = https://proxy.example.com:443
Or you may need to update the build config to have httpProxy and httpsProxy.
~]$ oc get buildconfig.build.openshift.io/s2i-python-container --output yaml
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
annotations:
openshift.io/generated-by: OpenShiftNewApp
creationTimestamp: "2024-10-16T09:28:34Z"
generation: 4
labels:
app: s2i-python-container
app.kubernetes.io/component: s2i-python-container
app.kubernetes.io/instance: s2i-python-container
name: s2i-python-container
namespace: my-project
resourceVersion: "346420048"
uid: 5e03a1d0-6205-438c-bf3b-9e7bf2afe60e
spec:
failedBuildsHistoryLimit: 5
nodeSelector: null
output:
to:
kind: ImageStreamTag
name: s2i-python-container:latest
postCommit: {}
resources: {}
runPolicy: Serial
source:
git:
httpProxy: http://proxy.example.com:80
httpsProxy: http://proxy.example.com:80
uri: https://github.com/sclorg/s2i-python-container
type: Git
strategy:
sourceStrategy:
from:
kind: ImageStreamTag
name: python-39:latest
type: Source
successfulBuildsHistoryLimit: 5
triggers:
- github:
secret: VpHcwDCRIyXRK_A38mGT
type: GitHub
- generic:
secret: -7K1RAYC1pAHLx8P0iSz
type: Generic
- type: ConfigChange
- imageChange: {}
type: ImageChange
The oc new-app command can then be used to see if you can deploy the app from GitHub.
oc new-app https://github.com/sclorg/s2i-python-container
Or you could create a JSON file such as s2i-python-container.json that contains the JSON needed to deploy the app and then use the oc create command with the -f or --filename option to deploy the app.
oc create --filename s2i-python-container.json
Something like this should be displayed.
--> Found container image 06c2af2 (16 months old) from registry.redhat.io for "registry.redhat.io/ubi8/python-39@sha256:e2a461928e82d7da8991f4fdf5496219f013a6e70c4ef30cf5fb93a4cc450eac"
Python 3.9
----------
Python 3.9 available as container is a base platform for building and running various Python 3.9 applications and frameworks. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.
Tags: builder, python, python39, python-39, rh-python39
* An image stream tag will be created as "python-39:latest" that will track the source image
* A source build using source code from https://github.com/sclorg/s2i-python-container will be created
* The resulting image will be pushed to image stream tag "s2i-python-container:latest"
* Every time "python-39:latest" changes a new build will be triggered
--> Creating resources ...
imagestream.image.openshift.io "python-39" created
imagestream.image.openshift.io "s2i-python-container" created
buildconfig.build.openshift.io "s2i-python-container" created
deployment.apps "s2i-python-container" created
service "s2i-python-container" created
--> Success
Build scheduled, use 'oc logs -f buildconfig/s2i-python-container' to track its progress.
Application is not exposed. You can expose services to the outside world by executing one or more of the commands below:
'oc expose service/s2i-python-container'
Run 'oc status' to view your app.
In this example, the Python app is a source to image, meaning there should be a build config for the app. In this scenario, the build must be able to reach https://github.com/sclorg/s2i-python-container.
~]$ oc get builds
NAME TYPE FROM STATUS STARTED DURATION
s2i-python-container-1 Source Git Running 21 seconds ago
Be aware that the image stream may not be tagged, which can cause something like this to be returned.
2m29s Warning BuildConfigInstantiateFailed buildconfig/s2i-python-container error instantiating Build from BuildConfig my-project/s2i-python-container (0): Error resolving ImageStreamTag python-39:latest in namespace my-project: unable to find latest tagged image
So you may want to include the --allow-missing-imagestream-tags option.
oc new-app https://github.com/sclorg/s2i-python-container --allow-missing-imagestream-tags
If something like this is returned . . .
error: unable to load template file "https://github.com/sclorg/nodejs-ex": error parsing https://github.com/sclorg/nodejs-ex: error converting YAML to JSON: yaml: line 28: mapping values are not allowed in this context
error: local file access failed with: stat https://github.com/sclorg/nodejs-ex: no such file or directory
error: unable to locate any images in image streams, templates loaded in accessible projects, template files, local docker images with name "https://github.com/sclorg/nodejs-ex"
Argument 'https://github.com/sclorg/nodejs-ex' was classified as an image, image~source, or loaded template reference.
The 'oc new-app' command will match arguments to the following types:
1. Images tagged into image streams in the current project or the 'openshift' project
- if you don't specify a tag, we'll add ':latest'
2. Images in the container storage, on remote registries, or on the local container engine
3. Templates in the current project or the 'openshift' project
4. Git repository URLs or local paths that point to Git repositories
--allow-missing-images can be used to point to an image that does not exist yet.
you can try including the --image-steam and --allow-missing-imagestream-tags options.
oc new-app https://github.com/sclorg/nodejs-ex --name nodejs --image-stream="openshift/nodejs" --allow-missing-imagestream-tags
If the deployment was successful, the oc get deployments command should return something like this.
~]# oc get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
s2i-python-container 1 1 1 8d
While the pod is being built, the oc get pods command should display something like this. Notice "build" in name.
NAME READY STATUS RESTARTS AGE
s2i-python-container-1-build 0/1 ContainerCreating 0 5s
Once the build has completed successfully, READY should update to 1/1 and STATUS should update to Running.
NAME READY STATUS RESTARTS AGE
s2i-python-container-1-build 1/1 Running 0 1m
Next, the deploy pod should be created. Once the deploy has completed successfully, the following should be displayed.
NAME READY STATUS RESTARTS AGE
s2i-python-container-1-deploy 1/1 Running 0 2m
If there is some issue with the build or deploy, something like this may be displayed.
NAME READY STATUS RESTARTS AGE
s2i-python-container-1-build 0/1 Init:0/2 0 15s
If the build pod fails to initialize, something like this should be displayed.
NAME READY STATUS RESTARTS AGE
s2i-python-container-1-build 0/1 Init:Error 0 4m
In this scenario, the oc describe pod command can be used to display the pod events.
oc describe pod/php-ex-1-build
Once the status of the pod is Running, the oc status command can be used.
oc status
Something like this should be displayed.
svc/php - 10.15.152.137 ports 8080, 8443
dc/httpd deploys openshift/php:7.1
deployment #1 running for about a minute - 0/1 pods
3 infos identified, use 'oc status --suggest' to see details.
Did you find this article helpful?
If so, consider buying me a coffee over at