Hello everyone. This is Aya Tokura.
This time, it's published on the ** IBM Developer ** site as ** Code Pattern ** ["Deploy a sample exchange app to OpenShift using Red Hat Universal Base Image. ]](Https://developer.ibm.com/jp/patterns/deploy-to-openshift-4-redhat-universal-base-image/) **, with operating procedures and additional comments as a Japanese reference translation I will also introduce it.
This article covers the steps to deploy a sample exchange application written in Python on Red Hat OpenShift on IBM Cloud using Red Hat Universal Base Image (UBI). After completing this operation, you will be able to acquire the following skills.
An image of an operating system for containers with Red Hat Enterprise Linux (RHEL) as the core. In other words, for users who are already using RHEL, it is possible to build an image that combines quality. You can create an image on any platform, redistribute it at will, and run it wherever you like. For more information, please visit the official Red Hat website.
Use a Red Hat OpenShift cluster on IBM Cloud as your cloud environment. If you have obtained an Open Shift on IBM Cloud environment for your workshop, such as at an IBM Developer Dojo OpenShift seminar, you can use it.
You need to have the following tools and environment ready. -Docker: Environment where Docker can be executed locally --Docker Hub account --IBM Cloud Account-- Pay-As-You-Go (PayG) --Red Hat OpenShift 4 clusters on Red Hat OpenShift on IBM Cloud
git clone https://github.com/IBM/python-ubi-openshift.git
cd python-ubi-openshift
<your-dockerhub-username>
, specify your own DockerHub user name and build and execute the Docker image locally.
export DOCKERHUB_USERNAME=<your-dockerhub-username>
docker build -t $DOCKERHUB_USERNAME/currencyexchange-py:v0.0.1 .
SETX DOCKERHUB_USERNAME "your-dockerhub-username"
docker build -t $DOCKERHUB_USERNAME/currencyexchange-py:v0.0.1 .
Sending build context to Docker daemon 69.63MB
Step 1/10 : FROM registry.access.redhat.com/ubi8/ubi
---> fd73e6738a95
...
Collecting flask (from -r requirements.txt (line 13))
Downloading https://files.pythonhosted.org/packages/9b/93/628509b8d5dc749656a9641f4caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl (94kB)
...
Successfully built 3b5631170697
Successfully tagged <DOCKERHUB_USERNAME>/currencyexchange-py:v0.0.1
docker run -p 7878:7878 $DOCKERHUB_USERNAME/currencyexchange-py:v0.0.1
You can verify that the Forex microservices docker container is running by opening another terminal and running the docker ps
command.
3. Access http://127.0.0.1:7878/ from your browser and try the API call from try-it-out
.
4. After confirming the operation, press [Control] + [C] at the same time in the terminal to finish.
In order to allow changes to this microservice, you need to create a repository in the Docker Cloud (https://hub.docker.com/) so that you can push the newly modified container.
<your-dockerhub-username>
, specify your Docker Hub username.
export DOCKERHUB_USERNAME=<your-dockerhub-username>
docker build -t $DOCKERHUB_USERNAME/currencyexchange-py:v0.0.1 .
docker login
docker push $DOCKERHUB_USERNAME/currencyexchange-py:v0.0.1
From here, use the oc command to deploy to OpenShift. * Recommended after v4.1.0
oc version
Log in to ** IBM Cloud Dashboard ** from your browser.
Go to your OpenShift cluster page and click the ** [OpenShift web console] ** button.
Click ** [Copy Login Command] ** from the drop-down menu next to your username in the upper right corner of the OpenShift console to get information to log in to OpenShfit from the command.
oc new-project currencyexchange-py
oc project
oc new-app $DOCKERHUB_USERNAME/currencyexchange-py:v0.0.1
▼ Example of displayed output contents In the yellow highlight section, you can see that ** Red Hat Universal Base Image ** is the base image for your Docker deployment.
oc expose svc/currencyexchange-py
oc status
▼ Example of displayed output contents The highlighted part is the URL information that is publicly available.
▼ Example of a site displayed by accessing the URL
You can use the ** OpenShift Web Console Dashboard ** to check the status of your microservices at any time.
You have now successfully created a Python Flask microservices container image using UBI and optionally deployed it to a RedHat OpenShift 4 cluster on IBM Cloud. This time is over. Thank you for your hard work.
★ The latest information is being delivered on Twitter @ayatokura
Recommended Posts