Bookmark this page

Guided Exercise: Creating Image Streams

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

  1. Log in to OpenShift and create a project to host the image stream for the Nginx container image.

    1. 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...
    2. 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...
  2. Create an image stream that points to the Nginx image from the external registry.

    1. 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...
      }
    2. 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...
    3. Verify that the hello-world:latest image stream tag is created.

      [student@workstation ~]$ oc get istag
      NAME                 IMAGE REF ...output omitted...
      hello-world:latest   registry.ocp4.example.com:8443/redhattraining/hello-world-nginx...output omitted...
    4. Verify that the image stream and its tag contain metadata about the Nginx container image.

      [student@workstation ~]$ oc describe is hello-world
      Name:          hello-world
      Namespace:     images-streams-common
      ...output omitted...
      Tags:          1
      
      latest
        tagged from registry.ocp4.example.com:8443/redhattraining/hello-world-nginx 1
      
        * registry.ocp4.example.com:8443/redhattraining/hello-world-nginx@sha256:4f4f...acc12
            2 minutes ago
      
      ...output omitted...

      1

      The image stream tag hello-world:latest references an image from the classroom Quay instance.

      2

      The asterisk (*) indicates that the latest image stream tag references only the particular image with the given SHA-256 identifier.

  3. Create a new project and deploy an application using the hello-world image stream from the images-streams-common project.

    1. 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...
    2. 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...
    3. Wait until the application pod is ready and running.

      [student@workstation ~]$ oc get pod
      NAME                     READY   STATUS    RESTARTS   AGE
      hello-6599bb7b9c-zk58m   1/1     Running   0          40s
    4. Create a route to expose the application.

      [student@workstation ~]$ oc expose svc hello
      route.route.openshift.io/hello exposed
  4. Verify that the application is exposed and works.

    1. 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...
    2. 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>

Finish

On the workstation machine, use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish images-streams

Revision: do288-4.12-0d49506