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.
Log in to Red Hat OpenShift.
[student@workstation ~]$ oc login -u developer -p developer \
https://api.ocp4.example.com:6443
Login successful.
...output omitted...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".Authenticate the default service account with the registry.ocp4.example.com:8443 container registry by using incorrect credentials.
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 createdLink the secret to the default service account.
[student@workstation ~]$oc secrets link default \ wrong-registry-credentials --for=pullno output expected
Create a deployment that uses the registry.ocp4.example.com:8443/redhattraining/hello-world-nginx:latest container image.
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 createdVerify the status of the application pods.
[student@workstation ~]$oc get poNAME READY STATUS RESTARTS AGE hello-world-nginx-65c6474c9f-zfdtb 0/1ImagePullBackOff0 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.
Change the default service account authentication to use the correct credentials.
Use the developer user, developer password, and developer@example.org email.
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 createdUnlink the wrong credentials from the default service account.
[student@workstation ~]$ oc secrets unlink default wrong-registry-credentials
serviceaccount/default updatedLink the secret to the default service account.
[student@workstation ~]$oc secrets link default registry-credentials --for=pullno output expected
Delete the current application pod.
[student@workstation ~]$ oc delete po -l app=hello-world-nginx
pod "hello-world-nginx-65c6474c9f-zfdtb" deletedVerify that the application started.
[student@workstation ~]$ oc get po
NAME READY STATUS RESTARTS AGE
hello-world-nginx-65c6474c9f-wrmvs 1/1 Running 0 37sRepeat 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