Bookmark this page

Guided Exercise: Using External Registries in Red Hat OpenShift

Use container images from remote container registries in Red Hat OpenShift.

Outcomes

  • Authenticate Red Hat OpenShift with an external registry.

  • Deploy a private container image to Red Hat OpenShift.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

[student@workstation ~]$ lab start images-registry

Instructions

Authenticate your Red Hat OpenShift instance with the registry.ocp4.example.com:8443 container registry.

  1. Log in to Red Hat OpenShift.

    [student@workstation ~]$ oc login -u developer -p developer \
    https://api.ocp4.example.com:6443
    Login successful.
    ...output omitted...
  2. Switch to the images-registry project.

    [student@workstation ~]$ oc project images-registry
    Already on project"images-registry" on server "https://api.ocp4.example.com:6443".
  3. Authenticate the default service account with the registry.ocp4.example.com:8443 container registry by using incorrect credentials.

    1. Create the wrong-registry-credentials secret of the docker-registry type that contains the credentials.

      [student@workstation ~]$ oc create secret docker-registry \
      wrong-registry-credentials \
      --docker-server=registry.ocp4.example.com:8443 \
      --docker-username=developer --docker-password=developer1 \
      --docker-email=developer@example.org
      secret/wrong-registry-credentials created
    2. Link the secret to the default service account.

      [student@workstation ~]$ oc secrets link default \
      wrong-registry-credentials --for=pull
      no output expected
  4. Create a deployment that uses the registry.ocp4.example.com:8443/redhattraining/hello-world-nginx:latest container image.

    1. Create the hello-world-nginx deployment that uses the registry.ocp4.example.com:8443/redhattraining/hello-world-nginx:latest container image.

      [student@workstation ~]$ oc create deployment hello-world-nginx \
      --image=registry.ocp4.example.com:8443/redhattraining/hello-world-nginx:latest
      Warning: would violate PodSecurity ...
      deployment.apps/hello-world-nginx created
    2. Verify the status of the application pods.

      [student@workstation ~]$ oc get po
      NAME                                 READY   STATUS             RESTARTS   AGE
      hello-world-nginx-65c6474c9f-zfdtb   0/1     ImagePullBackOff   0          3s

      See the failed event messages that the application emits.

      [student@workstation ~]$ oc get ev --field-selector type=Warning \
      -o jsonpath='{.items[].message}{"\n"}'
      Failed to pull image "registry.ocp4.example.com:8443/redhattraining/hello-world-nginx:latest": ... invalid username/password: unauthorized: ...

      OpenShift generates event messages to inform users about events in a project, for example the reason for failures.

  5. Change the default service account authentication to use the correct credentials.

    Use the developer user, developer password, and developer@example.org email.

    1. Create the registry-credentials secret of the docker-registry type that contains the credentials.

      [student@workstation ~]$ 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 created
    2. Unlink the wrong credentials from the default service account.

      [student@workstation ~]$ oc secrets unlink default wrong-registry-credentials
      serviceaccount/default updated
    3. Link the secret to the default service account.

      [student@workstation ~]$ oc secrets link default registry-credentials --for=pull
      no output expected
    4. Delete the current application pod.

      [student@workstation ~]$ oc delete po -l app=hello-world-nginx
      pod "hello-world-nginx-65c6474c9f-zfdtb" deleted
    5. Verify that the application started.

      [student@workstation ~]$ oc get po
      NAME                                 READY   STATUS    RESTARTS   AGE
      hello-world-nginx-65c6474c9f-wrmvs   1/1     Running   0          37s

      Repeat the command until the pod starts.

      See the event messages that the application emits.

      [student@workstation ~]$ oc get ev --sort-by='.lastTimestamp'
      ...output omitted...
      Successfully pulled image "registry.ocp4.example.com:8443/redhattraining/hello-world-nginx:latest" in 9.003716885s

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-registry

Revision: do288-4.12-0d49506