Outcomes
You should be able to inspect container images, list images of containers that run on compute nodes, and deploy applications by using image tags or SHA IDs.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that all resources are available for this exercise.
It also creates the updates-ids project and the /home/student/DO180/labs/updates-ids/resources.txt file.
The resources.txt file contains the name of the images and some commands that you use during the exercise.
You can use the file to copy and paste these image names and commands.
[student@workstation ~]$ lab start updates-ids
Instructions
Log in to the OpenShift cluster as the
developeruser with thedeveloperpassword. Use theupdates-idsproject.Log in to the OpenShift cluster.
[student@workstation ~]$
oc login -u developer -p developer \https://api.ocp4.example.com:6443Login successful. ...output omitted...Set the
updates-idsproject as the active project.[student@workstation ~]$
oc project updates-ids...output omitted...
Inspect the two versions of the
registry.ocp4.example.com:8443/ubi8/httpd-24image from the classroom container registry. The classroom setup copied that image from the Red Hat Ecosystem Catalog. The original image isregistry.access.redhat.com/ubi8/httpd-24.Use the
oc image infocommand to inspect the image version that the1-209tag references. Notice the unique SHA ID that identifies the image version.Note
To improve readability, the instructions truncate the SHA-256 strings.
On your system, the commands return the full SHA-256 strings. Also, you must type the full SHA-256 string, to provide such a parameter to a command.
[student@workstation ~]$
oc image info \registry.ocp4.example.com:8443/ubi8/httpd-24:1-209Name: registry.ocp4.example.com:8443/ubi8/httpd-24:1-209Digest:sha256:b1e3...f876...output omitted...Inspect the image version that the
1-215tag references. Notice that the SHA ID, or digest, differs from the preceding image version.[student@workstation ~]$
oc image info \registry.ocp4.example.com:8443/ubi8/httpd-24:1-215Name: registry.ocp4.example.com:8443/ubi8/httpd-24:1-215Digest:sha256:91ad...fd83...output omitted...For inspecting images, you can also use the
skopeo inspectcommand. The output format differs from theoc image infocommand, although both commands report similar data.Log in to the registry as the
developeruser with thedeveloperpassword by using theskopeo logincommand. Then, use theskopeo inspectcommand to inspect the1-215image tag.[student@workstation ~]$
skopeo login registry.ocp4.example.com:8443 -u developerPassword:developerLogin Succeeded![student@workstation ~]$
skopeo inspect \ docker://registry.ocp4.example.com:8443/ubi8/httpd-24:1-215{ "Name": "registry.ocp4.example.com:8443/ubi8/httpd-24", "Digest": "", "RepoTags": [ "1-209", "1-215" ], ...output omitted... }sha256:91ad...fd83The
skopeo inspectcommand also shows other existing image tags.
Deploy an application from the image version that the
1-209tag references.Use the
oc create deploymentcommand to deploy the application. Set the name of the deployment tohttpd1.[student@workstation ~]$
oc create deployment httpd1 \--image registry.ocp4.example.com:8443/ubi8/httpd-24:1-209deployment.apps/httpd1 createdWait for the pod to start, and then retrieve the name of the cluster node that runs it. You might have to rerun the command several times for the pod to report a
Runningstatus. The name of the pod on your system probably differs.[student@workstation ~]$
oc get pods -o wideNAME READY STATUS RESTARTS AGE IP NODE ... httpd1-6dff796d99-pm2x6 1/1Running0 19s 10.8.0.104master01...Retrieve the name of the container that is running inside the pod. The
crictl pscommand that you run in a following step takes the container name as an argument.[student@workstation ~]$
oc get deployment httpd1 -o wideNAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS ... httpd1 1/1 1 1 1m10shttpd-24...
Access the cluster node and then retrieve the image that the container is using.
You must log in as the
adminuser to access the cluster node. Use theredhatocppassword.[student@workstation ~]$
oc login -u admin -p redhatocpLogin successful. ...output omitted...Use the
oc debug nodecommand to access the cluster node.[student@workstation ~]$
oc debug node/master01Temporary namespace openshift-debug-flz4d is created for debugging node... Starting pod/master01-debug ... To use host binaries, run `chroot /host` Pod IP: 192.168.50.10 If you don't see a command prompt, try pressing enter.In the remote shell, run the
chroot /hostcommand.sh-4.4#
chroot /hostsh-4.4#Use the
crictl pscommand to confirm that thehttpd-24container is running. Add the-o yamloption to display the container details in YAML format.sh-4.4#
crictl ps --name httpd-24 -o yamlcontainers: - annotations: ...output omitted... image: annotations: {} image: registry.ocp4.example.com:8443/ubi8/httpd-24@sha256:b1e3...f876imageRef: registry.ocp4.example.com:8443/ubi8/httpd-24@sha256:b1e3...f876labels: ...output omitted... state:CONTAINER_RUNNINGNotice that the command refers to the image by its SHA ID, and not by the tag that you specified when you created the deployment resource.
Use the
crictl imagescommand to list the locally available images on the node. Theregistry.ocp4.example.com:8443/ubi8/httpd-24:1-209is in that list, because the local container engine pulled it when you deployed thehttpd1application.Note
The
IMAGE IDcolumn displays the local image identifier that the container engine assigns to the image. This identifier is not related to the SHA image ID that the container registry assigned to the image.Most
crictlcommands, such ascrictl imagesorcrictl rmi, accept a local image identifier instead of the full image name. For example, you can run thecrictl images 8ee59251acc93command as a short version of thecrictl images registry.ocp4.example.com:8443/ubi8/httpd-24:1-209command.sh-4.4#
crictl imagesIMAGE TAGIMAGE IDSIZE quay.io/openshift-release-dev/ocp-release <none> d52324cb88017 444MB quay.io/openshift-release-dev/ocp-v4.0-art-dev <none> 22e6e45df32af 468MB quay.io/openshift-release-dev/ocp-v4.0-art-dev <none> e798432938c49 503MB quay.io/openshift-release-dev/ocp-v4.0-art-dev <none> 3ca084e53b321 873MB ...output omitted...registry.ocp4.example.com:8443/ubi8/httpd-24 1-209 8ee59251acc93461MB ...output omitted...The preceding
crictl imagescommand does not display the SHA image IDs by default. Rerun the command and add the--digestsoption to display the SHA IDs. Also add the local image ID to the command to limit the output to theregistry.ocp4.example.com:8443/ubi8/httpd-24:1-209image.The command reports only the first characters of the SHA image ID. These characters match the SHA ID of the image that the
httpd-24container is using. Therefore, thehttpd-24container is using the expected image.sh-4.4#
crictl images --digestsIMAGE TAG DIGEST IMAGE ID ... registry.ocp4.example.com:8443/ubi8/httpd-24 1-2098ee59251acc93b1e3c572516d18ee59251acc93 ...Disconnect from the cluster node.
sh-4.4#
exitexit sh-4.4#exitexit Removing debug pod ... Temporary namespace openshift-debug-flz4d was removed. [student@workstation ~]$
Log in as the
developeruser and then deploy another application by using the SHA ID of the image as the digest.Log in to the OpenShift cluster as the
developeruser.[student@workstation ~]$
oc login -u developer -p developerLogin successful. ...output omitted...Rerun the
oc image infocommand to retrieve the SHA ID of the image version that the1-209tag references. Specify the JSON format for the command output. Parse the JSON output with thejq -rcommand to retrieve the value of the.digestobject. Export the SHA ID as the$IMAGEenvironment variable.[student@workstation ~]$
oc image info \registry.ocp4.example.com:8443/ubi8/httpd-24:1-209 -o json | \jq -r .digestsha256:b1e3...f876[student@workstation ~]$
IMAGE=sha256:b1e3...f876Use the
oc create deploymentcommand to deploy the application. Set the name of the deployment tohttpd2.[student@workstation ~]$
oc create deployment httpd2 \--image registry.ocp4.example.com:8443/ubi8/httpd-24@$IMAGEdeployment.apps/httpd2 createdConfirm that the new deployment refers to the image version by its SHA ID.
[student@workstation ~]$
oc get deployment httpd2 -o wideNAME READY ... CONTAINERS IMAGES ... httpd2 1/1 ... httpd-24 registry.../ubi8/httpd-24@sha256:b1e3...f876...
Update the
httpd2application by using a more recent image version.In the
httpd2deployment, update thehttpd-24container to use the image version that the1-215tag references.[student@workstation ~]$
oc set image deployment/httpd2 \httpd-24=registry.ocp4.example.com:8443/ubi8/httpd-24:1-215deployment.apps/httpd2 image updatedConfirm that the deployment refers to the new image version.
[student@workstation ~]$
oc get deployment httpd2 -o wideNAME READY ... IMAGES ... httpd2 1/1 ...registry.ocp4.example.com:8443/ubi8/httpd-24:1-215...Confirm that the deployment finished redeploying the pod. You might have to rerun the command several times for the pod to report a
Runningstatus. The pod names probably differ on your system.[student@workstation ~]$
oc get podsNAME READY STATUS RESTARTS AGE httpd1-6dff796d99-pm2x6 1/1 Running 0 118mhttpd2-998d9b9b9-5859j1/1Running0 21sInspect the pod to confirm that the container is using the new image. Replace the pod name with your own from the previous step.
[student@workstation ~]$
oc get pod httpd2-998d9b9b9-5859j\-o jsonpath='{.spec.containers[0].image}{"\n"}'registry.ocp4.example.com:8443/ubi8/httpd-24:1-215
Add the
latesttag to the image version that the1-209tag already references. Deploy an application from the image with thelatesttag.Use the
skopeo logincommand to log in to the classroom container registry as thedeveloperuser. Usedeveloperfor the password.[student@workstation ~]$
skopeo login -u developer -p developer \registry.ocp4.example.com:8443Login Succeeded!Use the
skopeo copycommand to add thelatesttag to the image.[student@workstation ~]$
skopeo copy \docker://registry.ocp4.example.com:8443/ubi8/httpd-24:1-209 \docker://registry.ocp4.example.com:8443/ubi8/httpd-24:latestGetting image source signatures ...output omitted... Writing manifest to image destination Storing signaturesUse the
oc image infocommand to confirm that both tags refer to the same image. The two commands report the same SHA image ID, which indicates that the tags point to the same image version.[student@workstation ~]$
oc image info \registry.ocp4.example.com:8443/ubi8/httpd-24:1-209Name: registry.ocp4.example.com:8443/ubi8/httpd-24:1-209 Digest:sha256:b1e3...f876...output omitted...[student@workstation ~]$
oc image info \registry.ocp4.example.com:8443/ubi8/httpd-24:latestName: registry.ocp4.example.com:8443/ubi8/httpd-24:latest Digest:sha256:b1e3...f876...output omitted...Use the
oc create deploymentcommand to deploy another application. Set the name of the deployment tohttpd3. To confirm that by default the command selects thelatesttag, do not provide the tag part in the image name.[student@workstation ~]$
oc create deployment httpd3 \--image registry.ocp4.example.com:8443/ubi8/httpd-24deployment.apps/httpd3 createdConfirm that the pod is running. You might have to rerun the command several times for the pod to report a
Runningstatus. The pod names probably differ on your system.[student@workstation ~]$
oc get podsNAME READY STATUS RESTARTS AGE httpd1-6dff796d99-pm2x6 1/1 Running 0 150m httpd2-998d9b9b9-5859j 1/1 Running 0 32mhttpd3-85b978d758-fvqdr1/1Running0 42sConfirm that the pod is using the expected image. Notice that the SHA image ID corresponds to the image that the
1-209tag references. You retrieved that SHA image ID in a preceding step when you ran theoc image infocommand.[student@workstation ~]$
oc describe pod httpd3-...output omitted... Containers: httpd-24: Container ID: cri-o://2cee...3a68 Image: registry.ocp4.example.com:8443/ubi8/httpd-24 Image ID: registry.ocp4.example.com:8443/ubi8/httpd-24@85b978d758-fvqdrsha256:b1e3...f876...output omitted...
Assign the
latesttag to a different image version. This operation simulates a developer who pushes a new version of an image and assigns thelatesttag to that new image version.Use the
skopeo copycommand to add thelatesttag to the image version that the1-215tag already references. The command automatically removes thelatesttag from the earlier image.[student@workstation ~]$
skopeo copy \docker://registry.ocp4.example.com:8443/ubi8/httpd-24:1-215 \docker://registry.ocp4.example.com:8443/ubi8/httpd-24:latestGetting image source signatures ...output omitted... Writing manifest to image destination Storing signaturesLog out of the classroom container registry.
[student@workstation ~]$
skopeo logout registry.ocp4.example.com:8443Removed login credentials for registry.ocp4.example.com:8443Note
The
skopeo logoutcommand logs out of a specified registry server by deleting the cached credentials that are stored in the${XDG_RUNTIME_DIR}/containers/auth.jsonfile.Red Hat recommends removing cached credentials that are no longer required.
Even though the
latesttag is now referencing a different image version, OpenShift does not redeploy the pods that are running with the previous image version.Rerun the
oc describe podcommand to confirm that the pod still uses the preceding image.[student@workstation ~]$
oc describe pod httpd3-...output omitted... Containers: httpd-24: Container ID: cri-o://2cee...3a68 Image: registry.ocp4.example.com:8443/ubi8/httpd-24 Image ID: registry.ocp4.example.com:8443/ubi8/httpd-24@85b978d758-fvqdrsha256:b1e3...f876...output omitted...
Scale the
httpd3deployment to two pods.Use the
oc scalecommand to add a new pod to the deployment.[student@workstation ~]$
oc scale deployment/httpd3 --replicas 2deployment.apps/httpd3 scaledList the pods to confirm that two pods are running for the
httpd3deployment. The pod names probably differ on your system.[student@workstation ~]$
oc get podshttpd1-6dff796d99-pm2x6 1/1 Running 0 75m httpd2-998d9b9b9-5859j 1/1 Running 0 30mhttpd3-85b978d758-f98jh1/1 Running 0 54shttpd3-85b978d758-fvqdr1/1 Running 0 11mRetrieve the SHA image ID for the pod that the deployment initially created. The ID did not change. The container is still using the original image version.
[student@workstation ~]$
oc describe pod httpd3-...output omitted... Containers: httpd-24: Container ID: cri-o://2cee...3a68 Image: registry.ocp4.example.com:8443/ubi8/httpd-24 Image ID: registry.ocp4.example.com:8443/ubi8/httpd-24@85b978d758-fvqdrsha256:b1e3...f876...output omitted...Retrieve the SHA image ID for the additional pod. Notice that the ID is different. The additional pod is using the image that the
latesttag is currently referencing.[student@workstation ~]$
oc describe pod httpd3-...output omitted... Containers: httpd-24: Container ID: cri-o://d254...c893 Image: registry.ocp4.example.com:8443/ubi8/httpd-24 Image ID: registry.ocp4.example.com:8443/ubi8/httpd-24@85b978d758-f98jhsha256:91ad...fd83...output omitted...The state of the deployment is inconsistent. The two replicated pods use a different image version. Consequently, the scaled application might not behave correctly. Red Hat recommends that you use a less volatile tag than
latestin production environments, or that you tightly control the tag assignments in your container registry.