
An image is basically an object that can be used to deploy an operating system to an OpenShift container, such as a Linux Red Hat operating system. These are typically small, lightweight operating systems that just contain the core features needed to run the operating system in an OpenShift container. Often, images come precompiled with certain features. For example, a Python image would contain the requirements needed to run a Python application in the container. A Node.js image would contain the requirements needed to run a Node.js application in the container.
A deployment includes a certain image and the deployment creates a replica set (which is the number of pods that should be created) and then the replica set should spawn pods, and each pod should include a container. The container runs the operating system.
If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
The oc get images command can be used to list the images that have already been imported into your OpenShift cluster. In this example, there are a few images.
- nginx version 118 for Red Hat Enterprise Linux 8 (RHEL8)
- Python version 3.11
- Node.js version 20
- JBoss Enterprise Application Platform (EAP) version 7.4
~]# oc get images
NAME IMAGE REFERENCE
sha256:0089883f8e4387618946cd24378a447b8cf7e5dfaa146b94acab27fc5e170a14 registry.example.com/jboss-webserver-3/webserver30-tomcat8-openshift@sha256:0089883f8e4387618946cd24378a447b8cf7e5dfaa146b94acab27fc5e170a14
sha256:0155e28b6b10d6fba7144df9ce33105acbab32766836baacc67c76b900a58772 registry.example.com/redhat-sso-7/sso70-openshift@sha256:0155e28b6b10d6fba7144df9ce33105acbab32766836baacc67c76b900a58772
sha256:03416282b034b93614ab2af74441ce481226bcf0b0b6c614cacd1b6f008f9792 registry.example.com/jboss-eap-6/eap64-openshift@sha256:03416282b034b93614ab2af74441ce481226bcf0b0b6c614cacd1b6f008f9792
sha256:03795eb1e54f94ffb822b8b3997b5f5bbeaa20bdf7006841864738d1eb58054b registry.example.com/rhpam-7/rhpam72-businesscentral-openshift@sha256:03795eb1e54f94ffb822b8b3997b5f5bbeaa20bdf7006841864738d1eb58054b
The oc import-image command can be used to import an image from an external registry, such as registry.redhat.io, registry.access.redhat.com, registry.ci.openshift.org, and the list goes on. In this example, an image named openjdk18 is imported from registry.access.redhat.com.
~]$ oc import-image openjdk18 --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift --confirm
imagestream.image.openshift.io/openjdk18 imported
If the image is stored in a secured external registry, you may need to use the podman login command to log into the external registry.
sudo podman login registry.redhat.io
And then use the podman pull command to pull the image from the external registry.
sudo podman pull registry.redhat.io/openshift4/ose-hello-openshift-rhel8:v4.7.0-202205312157.p0.g7706ed4.assembly.stream
Now the oc get images command should include the imported image.
~]$ oc get images
NAME IMAGE REFERENCE
sha256:6f75262945716ac8f9bdcf1c26ba2eb962764f0e89ba1745933be553a6b58aa4 registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift@sha256:6f75262945716ac8f9bdcf1c26ba2eb962764f0e89ba1745933be553a6b58aa4
And the oc get imagestreams command should also include the imported image.
~]$ oc get imagestream openjdk18
NAME IMAGE REPOSITORY TAGS UPDATED
openjdk18 image-registry.openshift-image-registry.svc:5000/foo/openjdk18 latest 15 hours ago
You can then create a deployment using an image.
- Deploy Python container on OpenShift
- Deploy Python Flask container on OpenShift
- Deploy an application from an image
For example, you could have the following YAML which uses "registry.redhat.io/ubi9/python-39@sha256:0c2f708b4977469d090719d939778eb95b42c02c1da6476aa95f2e875920652b" as the image to run app.py using Python version 3.9.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: my-project
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- command:
- /bin/sh
- -c
- python /opt/app-root/src/app.py
image: registry.redhat.io/ubi9/python-39@sha256:0c2f708b4977469d090719d939778eb95b42c02c1da6476aa95f2e875920652b
name: my-container
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- mountPath: /opt/app-root/src/app.py
name: my-config-map
subPath: app.py
volumes:
- configMap:
defaultMode: 420
name: my-config-map
name: my-config-map
Did you find this article helpful?
If so, consider buying me a coffee over at