Create and manage Red Hat OpenShift Image Streams.
Outcomes
Publish an image from an external registry as an image stream in OpenShift.
Deploy an application using the image stream.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command validates that the cluster is available and deploys an example application in a new project.
[student@workstation ~]$ lab start images-streams
Instructions
Log in to OpenShift and create a project to host the image stream for the Nginx container image.
Log in to OpenShift using the developer user account.
[student@workstation ~]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...Create a project to host the image streams that are potentially shared among multiple projects.
[student@workstation ~]$ oc new-project images-streams-common
Now using project "images-streams-common" on server "registry.ocp4.example.com:8443".
...output omitted...Create an image stream that points to the Nginx image from the external registry.
Verify that the redhattraining/hello-world-nginx image from the registry has a tag called latest.
[student@workstation ~]$ skopeo login registry.ocp4.example.com:8443 \
-u developer -p developer
Login Succeeded![student@workstation ~]$skopeo inspect \ docker://registry.ocp4.example.com:8443/redhattraining/hello-world-nginx{ "Name": "registry.ocp4.example.com:8443/redhattraining/hello-world-nginx", "Digest": "sha256:...output omitted..." "RepoTags": [ "v1.0","latest"], ...output omitted... }
Create the hello-world image stream that points to the redhattraining/hello-world-nginx container image from the registry.
[student@workstation ~]$ oc import-image hello-world --confirm \
--from registry.ocp4.example.com:8443/redhattraining/hello-world-nginx
imagestream.image.openshift.io/hello-world imported
Name: hello-world
Namespace: images-streams-common
...output omitted...
Unique Images: 1
Tags: 1
latest
tagged from registry.ocp4.example.com:8443/redhattraining/hello-world-nginx
...output omitted...Verify that the hello-world:latest image stream tag is created.
[student@workstation ~]$oc get istagNAME IMAGE REF ...output omitted...hello-world:latestregistry.ocp4.example.com:8443/redhattraining/hello-world-nginx...output omitted...
Verify that the image stream and its tag contain metadata about the Nginx container image.
[student@workstation ~]$oc describe is hello-worldName: hello-world Namespace: images-streams-common ...output omitted... Tags: 1 latest tagged from registry.ocp4.example.com:8443/redhattraining/hello-world-nginx* registry.ocp4.example.com:8443/redhattraining/hello-world-nginx@sha256:4f4f...acc1
2 minutes ago ...output omitted...
Create a new project and deploy an application using the hello-world image stream from the images-streams-common project.
Create a project to host the test application.
[student@workstation ~]$ oc new-project images-streams-app
Now using project "images-streams-app" on server "registry.ocp4.example.com:8443".
...output omitted...Deploy an application from the image stream.
[student@workstation ~]$ oc new-app --name hello \
-i images-streams-common/hello-world
--> Found image ...output omitted...
...output omitted...
--> Creating resources ...
deployment.apps "hello" created
service "hello" created
--> Success
...output omitted...Wait until the application pod is ready and running.
[student@workstation ~]$oc get podNAME READY STATUS RESTARTS AGE hello-6599bb7b9c-zk58m1/1Running0 40s
Create a route to expose the application.
[student@workstation ~]$ oc expose svc hello
route.route.openshift.io/hello exposedVerify that the application is exposed and works.
Get the host name of the route.
[student@workstation ~]$ oc get route
NAME HOST/PORT ...output omitted...
hello hello-images-streams-app.apps.ocp4.example.com ...output omitted...Test the application using the curl command and the host name from the previous step.
[student@workstation ~]$ curl \
http://hello-images-streams-app.apps.ocp4.example.com
<html>
<body>
<h1>Hello, world from nginx!</h1>
</body>
</html>