Deploy container images from private registries by using Image Streams.
Outcomes
Build a container image locally.
Publish a container image to a private image registry.
Create an image stream from a container image in a private registry.
Create an application using a new image stream.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that the required files are in the lab ~/DO288/labs/images-review directory and that the images-review project exists in the Red Hat OpenShift cluster.
[student@workstation ~]$ lab start images-review
Instructions
Use the following as the input data for the required actions:
| Application name |
custom-server
|
| Image name |
custom-server:1.0.0
|
| Image registry |
registry.ocp4.example.com:8443
|
| Registry username |
developer
|
| Registry password |
developer
|
| Registry email |
developer@example.org
|
| Registry secret name |
registry-credentials
|
Build the container image in the ~/DO288/labs/images-review directory.
Go to the location of the container that the exercise provides.
[student@workstation ~]$ cd ~/DO288/labs/images-reviewReview the Containerfile contents.
[student@workstation images-review]$ cat Containerfile
FROM registry.ocp4.example.com:8443/redhattraining/hello-world-nginx:latest
USER root
RUN sed -i "s/nginx/OpenShift/g" /usr/share/nginx/html/index.html
USER 1001Log in to the classroom container registry.
[student@workstation images-review]$ podman login -u developer -p developer \
registry.ocp4.example.com:8443
Login Succeeded!Build the container image.
[student@workstation images-review]$ podman build . \
-t registry.ocp4.example.com:8443/developer/custom-server:1.0.0
STEP 1/4: FROM registry.ocp4.example.com:8443/redhattraining/hello-world-nginx:latest
STEP 2/4: USER root
--> c8bd9df97f6
STEP 3/4: RUN sed -i "s/nginx/OpenShift/g" /usr/share/nginx/html/index.html
--> a09383c6d5e
STEP 4/4: USER 1001
COMMIT registry.ocp4.example.com:8443/developer/custom-server:1.0.0
--> afef715ff1d
Successfully tagged registry.ocp4.example.com:8443/developer/custom-server:1.0.0
afef715ff1daffe01e1f0a225fbaa089ee28617d23e9ffc4e91f4f6f75c32faaPush the custom-server image to the classroom private registry.
Create a secret called registry-credentials to access the private registry by using the data that the exercise provides.
Log in to Red Hat OpenShift.
[student@workstation images-review]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Ensure that you are in the images-review project.
[student@workstation images-review]$ oc project images-review
Already on project"images-review" on server "https://api.ocp4.example.com:6443".Create the registry-credentials secret of the docker-registry type that contains the credentials.
[student@workstation images-review]$ oc create secret docker-registry \
registry-credentials \
--docker-server=registry.ocp4.example.com:8443 \
--docker-username=developer \
--docker-password=developer \
--docker-email=developer@example.org
secret/registry-credentials createdLink the secret to the default service account.
[student@workstation images-review]$oc secrets link default \ registry-credentials --for=pullno output expected
Create an image stream for the custom-server:1.0.0 image that you pushed to the classroom registry.
Create the custom-server image stream that points to the container image that you pushed to the registry.
[student@workstation images-review]$ oc import-image custom-server --confirm \
--from registry.ocp4.example.com:8443/developer/custom-server:1.0.0
imagestream.image.openshift.io/custom-server imported
Name: custom-server
Namespace: images-review
...output omitted...
Unique Images: 1
Tags: 1
latest
tagged from registry.ocp4.example.com:8443/developer/custom-server:1.0.0
...output omitted...Create an OpenShift application by using the custom-server image stream.
Deploy an application by using the image stream.
[student@workstation images-review]$ oc new-app --name custom-server \
-i images-review/custom-server
--> Found image ...output omitted...
...output omitted...
--> Creating resources ...
deployment.apps "custom-server" created
service "custom-server" created
--> Success
...output omitted...Wait until the application pod is ready and running.
[student@workstation images-review]$oc get podNAME READY STATUS RESTARTS AGE custom-server-7d597c89c4-lng8p1/1Running0 30s
Validate that the application works by using the route URL and by verifying that the Hello, world from OpenShift! string shows in the response.
Create a route to expose the application.
[student@workstation images-review]$ oc expose svc custom-server
route.route.openshift.io/custom-server exposedGet the hostname of the route.
[student@workstation images-review]$ oc get route
NAME HOST/PORT ...output omitted...
custom-server custom-server-images-review.apps.ocp4.example.com ...output omitted...Test the application by using the curl command and the hostname from the previous step.
[student@workstation images-review]$ curl \
http://custom-server-images-review.apps.ocp4.example.com
<html>
<body>
<h1>Hello, world from OpenShift!</h1>
</body>
</html>