Outcomes
Add an image trigger to a deployment.
Modify an image stream tag to point to a new image.
Watch the rollout of the application.
Roll back a deployment to the previous image.
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-triggers project and deploys a web application with 10 replicas.
The command creates the /home/student/DO180/labs/updates-triggers/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-triggers
Instructions
Log in to the OpenShift cluster as the
developeruser with thedeveloperpassword. Use theupdates-triggersproject.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-triggersproject as the active project.[student@workstation ~]$
oc project updates-triggers...output omitted...
Inspect the
versioned-helloimage stream that thelabcommand created.Verify that the
labcommand enabled the local lookup policy for theversioned-helloimage stream.[student@workstation ~]$
oc set image-lookupNAME LOCAL versioned-hellotrueVerify that the
labcommand created theversioned-hello:1image stream tag. The image stream tag refers to the image in the classroom registry by its SHA ID.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 get istagNAME IMAGE REFERENCE ...versioned-hello:1...:8443/redhattraining/versioned-hello@sha256:66e0...105e...Verify that the
labcommand created theversioned-hello:1image stream tag from theregistry.ocp4.example.com:8443/redhattraining/versioned-hello:1-123image.[student@workstation ~]$
oc get istag versioned-hello:1 \-o jsonpath='{.tag.from.name}{"\n"}'registry.ocp4.example.com:8443/redhattraining/versioned-hello:1-123
Inspect the
Deploymentobject that thelabcommand created. Verify that the application is available from outside the cluster.List the
Deploymentobjects. Theversiondeployment retrieved the SHA image ID from theversioned-hello:1image stream tag. TheDeploymentobject includes a container namedversioned-hello. You use that information in a later step, when you configure the trigger.[student@workstation ~]$
oc get deployment -o wideNAME READY ... CONTAINERS IMAGES ... version 10/10 ...versioned-hello.../versioned-hello@sha256:66e0...105e...Open a new terminal.
Run the
/home/student/DO180/labs/updates-triggers/curl_loop.shscript that thelabcommand prepared. The script sends web requests to the application in a loop. Leave the script running and do not interrupt it.[student@workstation ~]$
/home/student/DO180/labs/updates-triggers/curl_loop.shHi! Hi! Hi! Hi! ...output omitted...
Add an image trigger to the
Deploymentobject.Switch back to the first terminal window, and then use the
oc set triggerscommand to add the trigger for theversioned-hello:1image stream tag to theversioned-hellocontainer.[student@workstation ~]$
oc set triggers deployment/version \--from-image versioned-hello:1 --containers versioned-hellodeployment.apps/version triggers updatedReview the definition of the trigger from the
image.openshift.io/triggersannotation.[student@workstation ~]$
oc get deployment version \-o jsonpath='{.metadata.annotations.image\.openshift\.io/triggers}' | jq .[ { "from": { "kind": "ImageStreamTag", "name": "versioned-hello:1" }, "fieldPath": "spec.template.spec.containers[?(@.name==\"versioned-hello\")].image" } ]
Update the
versioned-hello:1image stream tag to point to the1-125tag of theregistry.ocp4.example.com:8443/redhattraining/versioned-helloimage. Watch the output of thecurl_loop.shscript to verify that theDeploymentobject automatically rolls out.Use the
oc tagcommand to update theversioned-hello:1tag.[student@workstation ~]$
oc tag \registry.ocp4.example.com:8443/redhattraining/versioned-hello:1-125 \versioned-hello:1Tag versioned-hello:1 set to registry.ocp4.example.com:8443/redhattraining/versioned-hello:1-125.Changing the image stream tag triggered a rolling update. Watch the output of the
curl_loop.shscript in the second terminal.Before the update, only pods that use the earlier version of the image reply. During the rolling updates, both old and new pods respond. After the update, only pods that run the latest version of the image reply. The following output probably differs on your system.
...output omitted... Hi! Hi! Hi! Hi! Hi! v1.1 Hi! v1.1 Hi! Hi! v1.1 Hi! Hi! v1.1 Hi! v1.1 Hi! v1.1 Hi! v1.1 ...output omitted...
Do not stop the script.
Inspect the
Deploymentobject and the image stream.List the
versiondeployment and notice that the image changed.[student@workstation ~]$
oc get deployment version -o wideNAME READY ... CONTAINERS IMAGES ... version 10/10 ... versioned-hello .../versioned-hello@sha256:834d...fcb4...Display the details of the
versioned-helloimage stream. Theversioned-hello:1image stream tag points to the image with the same SHA ID as in theDeploymentobject.Notice that the preceding image is still available. In the following step, you roll back to that image by specifying its SHA ID.
[student@workstation ~]$
oc describe is versioned-helloName: versioned-hello Namespace: updates-triggers ...output omitted...1tagged from registry.ocp4.example.com:8443/redhattraining/versioned-hello:1-125* registry.ocp4.example.com:8443/.../versioned-hello@sha256:834d...fcb46 minutes ago registry.ocp4.example.com:8443/.../versioned-hello@sha256:66e0...105e 37 minutes ago
Roll back the
Deploymentobject by reverting theversioned-hello:1image stream tag.Use the
oc tagcommand. For the source image, copy and paste the old image name and the SHA ID from the output of the preceding command.[student@workstation ~]$
oc tag \registry.ocp4.example.com:8443/redhattraining/versioned-hello@sha256:66e0...105e \versioned-hello:1Tag versioned-hello:1 set to registry.ocp4.example.com:8443/redhattraining/versioned-hello@sha256:66e0...105e.Watch the output of the
curl_loop.shscript in the second terminal. The pods that run thev1.0version of the application are responding again. The following output probably differs on your system....output omitted... Hi! v1.1 Hi! v1.1 Hi! v1.1 Hi! v1.1 Hi! Hi! v1.1 Hi! v1.1 Hi! v1.1 Hi! Hi! v1.1 Hi! v1.1 Hi! Hi! Hi! ...output omitted...
Press Ctrl+C to quit the script. Close that second terminal when done.