Tutorial
Three ways to deploy a Python app into an OpenShift cluster
Compare OpenShift Source-to-Image with two other ways to deploy on Red Hat OpenShift on IBM Cloud
On this page
This tutorial shows you how to deploy a Python application into an OpenShift cluster on the cloud. You can also use the methodology described here to deploy applications or microservices developed on other runtime environments. The examples in this tutorial use Red Hat® OpenShift® on IBM Cloud™
This tutorial covers three deployment scenarios to build and deploy applications to an OpenShift cluster on IBM Cloud:
An existing Docker image needs to be pushed to the OpenShift cluster on IBM Cloud, and then deployed: In this scenario, an existing Docker image is in a private registry. The image must be deployed on the OpenShift cluster on IBM Cloud. For example, you might use this deployment scenario in a "lift and shift" approach during application modernization. There is no continuous integration or delivery mechanism that is implemented, because you don't have access to the sources.
There is a GitHub repo with sources as well as a Dockerfile that has instructions to assemble the image: This scenario is applicable when you want complete control and flexibility to assemble the image with the only the required dependencies and versions. The code is always compatible with the dependencies, because you specify them. You need to maintain the Dockerfile in this scenario, which can be a complex task at times. This scenario allows continuous integration and delivery to the OpenShift cluster, which helps keep the deployed version of the code current.
There is a GitHub repo with sources: In this scenario, you rely on the OpenShift Source to Image (S2I) toolkit to create a Docker image. OpenShift S2I uses the sources and a builder image to create a new Docker image. When the
oc new-app ...
command is used and noDockerfile
exists in the repository, the source code language is auto-detected. The language detection rules are specified here. According to the OpenShift blog, the advantages of using S2I are speed, patchability, user efficiency, and ecosystem. This scenario also allows a continuous integration and delivery to the OpenShift cluster, which helps keep the deployed version of the code current.
Prerequisites
You need an IBM Cloud Account, the OpenShift CLI and Docker.
Estimated time
Completing this tutorial should take about 30 minutes.
Step 1. Create an OpenShift cluster instance
Create a new instance of an OpenShift cluster. Select an appropriate plan and click Create.
Step 2. Deploy the application using a Docker image in a local registry
A GitHub repo with examples at github.com/IBM/deploy-python-openshift-tutorial contains sources and a Dockerfile. This tutorial uses these examples to assemble a Docker image and later deploy it to the OpenShift cluster.
Clone the GitHub repo by running the following command:
Build a Docker image of the application that needs to be deployed to an OpenShift cluster:
Open the OpenShift web console:
Log in to OpenShift using the CLI and create a new project:
Create a route for the Docker registry:
The output looks like the following example:
Run the following command to create a route for the Docker registry:
Check the create route details:
You should get an output that looks like the following example:
Observe the pattern of the registry url -
docker-registry-default.<cluster_name>-<ID_string>.<region>.containers.appdomain.cloud
.Make a note of the Docker registry URL. It is required in subsequent steps.
Log in to the Docker registry using the Docker CLI.
Note: Use the Docker registry URL noted earlier.
Tag the Docker image as shown in the following example:
Push the Docker image to the OpenShift Docker registry:
Deploy the image to OpenShift and expose the route:
Click the Open Url icon on the OpenShift console for the
helloworldpython
application:Hello, world!
is displayed in the browser window:
Step 3. Deploy the application using a GitHub repo with sources and a Dockerfile
This step uses the same GitHub repo github.com/IBM/deploy-python-openshift-tutorial for the deployment. The Dockerfile contains instructions to assemble the image.
The examples in this step use the exampleproject
you created earlier.
Run the following command to deploy the application:
Click the Open Url icon on the OpenShift console for the deploy-python-openshift-tutorial
application.
Hello, world!
is displayed in the browser window:
Step 4. Deploy the application using a GitHub repo with sources
This step uses the same GitHub repo github.com/IBM/deploy-python-openshift-tutorial for the deployment. Here, the OpenShift S2I uses a Builder image and its sources to create a new Docker image that is deployed to the OpenShift cluster:
Click the Open Url icon on the OpenShift console for the deploy-python-openshift-s2i-tutorial
application:
Hello, world!
is displayed in the browser window:
Summary
Now you know three different ways to build and deploy applications to an OpenShift cluster. You can try your own deployments with Red Hat OpenShift on IBM Cloud.
Next steps
Perhaps you're ready to use Tekton pipelines to build and deploy Docker images.