Lab: Troubleshoot and Scale Applications
Navigate the OpenShift web console to identify CPU-consuming workloads.
Troubleshoot and fix a failed MySQL pod.
Manually scale an application.
Configure health probes.
Outcomes
You should be able to troubleshoot malfunctioning workloads, configure deployments, and scale applications.
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. The command also creates the compreview-scale project and deploys some applications in that project.
The command creates the /home/student/DO180/labs/compreview-scale/resources.txt file. The resources.txt file contains the URLs of your OpenShift cluster and the name of the images that you use during the exercise. You can use the file to copy and paste these URLs and image names.
[student@workstation ~]$ lab start compreview-scale
Specifications
The API URL of your OpenShift cluster is https://api.ocp4.example.com:6443, and the oc command is already installed on your workstation machine.
The URL of the OpenShift web console is https://console-openshift-console.apps.ocp4.example.com. When you access the web console, select Red Hat Identity Management as the authentication mechanism.
Log in to the OpenShift cluster as the developer user with the developer password. The password for the admin user is redhatocp.
Perform the following tasks to complete the comprehensive review:
A pod in the cluster is consuming excessive CPU and is interfering with other tasks. Identify the pod and remove its workload.
The
compreview-scaleproject already includes a web application at http://frontend-compreview-scale.apps.ocp4.example.com. When you access this URL, the application returns a list of quotations from famous authors. The application is broken for now, and is missing some configuration to be ready for production.The application uses two Kubernetes
Deploymentobjects. Thefrontenddeployment provides the application web pages, and relies on thequotesdbdeployment that runs a MySQL database. Thelabcommand already created the services and routes that connect the application components and that make the application available from outside the cluster.Fix the application and make it ready for production:
The
quotesdbdeployment in thecompreview-scaleproject starts a MySQL server, but the database is failing. Review the logs of the pod to identify and then fix the issue.Use the following parameters for the database:
| Name | Value | | --- | --- | | Username |
operator1| | Password |redhat123| | Database name |quotes|You security team validated a new version of the MySQL container image that fixes a security issue. The new container image is
registry.ocp4.example.com:8443/rhel9/mysql-80:1-237.Update the
quotesdbdeployment to use this image. Ensure that the database redeploys.The classroom setup copied the image from the Red Hat Ecosystem Catalog. The original image is
registry.redhat.io/rhel9/mysql-80:1-237.Add a probe to the
quotesdbdeployment so that OpenShift can detect when the database is ready to accept requests. Use themysqladmin pingcommand for the probe.Add a second probe that regularly verifies the status of the database. Use the
mysqladmin pingcommand as well.Configure CPU and memory usage for the
quotesdbdeployment. The deployment needs 200 millicores of CPU and 256 MiB of memory to run, and you must restrict its CPU usage to 500 millicores and its memory usage to 1 GiB.Add a probe to the
frontenddeployment so that OpenShift can detect when the web application is ready to accept requests. The application is ready when an HTTP request on port 8000 to the/statuspath is successful.Add a second probe that regularly verifies the status of the web front end. The front end works as expected when an HTTP request on port 8000 to the
/envpath is successful.Configure CPU and memory usage for the
frontenddeployment. The deployment needs 200 millicores of CPU and 256 MiB of memory to run, and you must restrict its CPU usage to 500 millicores and its memory usage to 512 MiB.Scale the
frontendapplication to three pods to accommodate for the estimated production load.To verify your work, access the http://frontend-compreview-scale.apps.ocp4.example.com URL. The application returns a list of quotations from famous authors.
Use the OpenShift web console to identify and then delete the pod that consumes excessive CPU.
Use a web browser to access the https://console-openshift-console.apps.ocp4.example.com URL.
Select Red Hat Identity Management, and then log in as the
adminuser with theredhatocppassword. Click Skip tour if the Welcome to the Developer Perspective message is displayed.Switch to the Administrator perspective and then navigate to Observe → Dashboards.

Select the Kubernetes / Compute Resources / Cluster dashboard, and then click Inspect in the CPU Usage graph.

Set the zoom to five minutes and then hover over the graph. Notice that the interface lists the
compreview-scale-loadnamespace in the first position, which indicated that this namespace is the first CPU consumer.
Navigate to Observe → Dashboards and then select the Kubernetes / Compute Resources / Namespace (Workloads) dashboard. Select the
compreview-scale-loadnamespace and then set the time range to the last five minutes. Thecomputeprimedeployment is the workload that consumes excessive CPU.
Navigate to Workloads → Deployments and then select the
compreview-scale-loadproject. Select the menu for thecomputeprimedeployment and then click Delete Deployment. Click Delete to confirm the operation.
Review the logs of the pod that is failing for the
quotesdbdeployment. Set the missing environment variables in thequotesdbdeployment.Log in to the OpenShift cluster from the command line.
[student@workstation ~]$ oc login -u developer -p developer \ https://api.ocp4.example.com:6443 Login successful. ...output omitted...Set the
compreview-scaleproject as the active project.[student@workstation ~]$ oc project compreview-scale ...output omitted...List the pods to identify the failing pod from the
quotesdbdeployment. The names of the pods on your system probably differ.[student@workstation ~]$ oc get pods NAME READY STATUS RESTARTS AGE frontend-5fb85b4c75-5s7xr 0/1 CrashLoopBackOff 14 (2m52s ago) 50m quotesdb-9b9776479-4z4g9 0/1 CrashLoopBackOff 14 (3m4s ago) 50mRetrieve the logs for the failing pod. Some environment variables are missing.
[student@workstation ~]$ oc logs quotesdb-9b9776479-4z4g9 => sourcing 20-validate-variables.sh ... You must either specify the following environment variables: MYSQL_USER (regex: '^[a-zA-Z0-9_]+$') MYSQL_PASSWORD (regex: '[a-zA-Z0-9_~!@#$%&*()-=<>,.?;:|]+$') MYSQL_DATABASE (regex: '^[a-zA-Z0-9_]+$') ...output omitted...Add the missing environment variables to the
quotesdbdeployment. Ignore the warning message.[student@workstation ~]$ oc set env deployment/quotesdb \ MYSQL_USER=operator1 MYSQL_PASSWORD=redhat123 MYSQL_DATABASE=quotes Warning: would violate PodSecurity "restricted:v1.24": ...output omitted... deployment.apps/quotesdb updated
Update the MySQL container image for the
quotesdbdeployment.Retrieve the name of the container that is running inside the pod. You need the container name to update its image.
[student@workstation ~]$ oc get deployment/quotesdb -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS ... quotesdb 1/1 1 1 59m mysql-80 ...Set the image to
registry.ocp4.example.com:8443/rhel9/mysql-80:1-237. Ignore the warning message.[student@workstation ~]$ oc set image deployment/quotesdb \ mysql-80=registry.ocp4.example.com:8443/rhel9/mysql-80:1-237 Warning: would violate PodSecurity "restricted:v1.24": ...output omitted... deployment.apps/quotesdb image updatedVerify your work.
[student@workstation ~]$ oc get deployment/quotesdb -o wide NAME ... CONTAINERS IMAGES quotesdb ... mysql-80 registry.ocp4.example.com:8443/rhel9/mysql-80:1-237Wait for the deployment to roll out. 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 NAME READY STATUS RESTARTS AGE frontend-5fb85b4c75-5s7xr 0/1 CrashLoopBackOff 15 (3m39s ago) 56m quotesdb-54d64749c4-chhq6 1/1 Running 0 106s
Add a readiness and a liveness probe to the
quotesdbdeployment that runs themysqladmin pingcommand.Use the
oc set probecommand with the--readinessoption to add the readiness probe. Ignore the warning message.[student@workstation ~]$ oc set probe deployment/quotesdb \ --readiness -- mysqladmin ping Warning: would violate PodSecurity "restricted:v1.24": ...output omitted... deployment.apps/quotesdb probes updatedUse the
oc set probecommand with the--livenessoption to add the liveness probe. Ignore the warning message.[student@workstation ~]$ oc set probe deployment/quotesdb \ --liveness -- mysqladmin ping Warning: would violate PodSecurity "restricted:v1.24": ...output omitted... deployment.apps/quotesdb probes updated
Define resource limits for the
quotesdbdeployment. Set the CPU request to 200 millicores and the memory request to 256 MiB. Set the CPU limit to 500 millicores and the memory limit to 1 GiB. Ignore the warning message.[student@workstation ~]$ oc set resources deployment/quotesdb \ --requests cpu=200m,memory=256Mi --limits cpu=500m,memory=1Gi Warning: would violate PodSecurity "restricted:v1.24": ...output omitted... deployment.apps/quotesdb resource requirements updatedAdd a readiness and a liveness probe to the
frontenddeployment.Use the
oc set probecommand with the--readinessoption to add the readiness probe that tests the/statuspath on HTTP port 8000. Ignore the warning message.[student@workstation ~]$ oc set probe deployment/frontend --readiness \ --get-url http://:8000/status Warning: would violate PodSecurity "restricted:v1.24": ...output omitted... deployment.apps/frontend probes updatedUse the
oc set probecommand with the--livenessoption to add the liveness probe that tests the/envpath on HTTP port 8000. Ignore the warning message.[student@workstation ~]$ oc set probe deployment/frontend --liveness \ --get-url http://:8000/env Warning: would violate PodSecurity "restricted:v1.24": ...output omitted... deployment.apps/frontend probes updated
Define resource limits for the
frontenddeployment. Set the CPU request to 200 millicores and the memory request to 256 MiB. Set the CPU limit to 500 millicores and the memory limit to 512 MiB. Ignore the warning message.[student@workstation ~]$ oc set resources deployment/frontend \ --requests cpu=200m,memory=256Mi --limits cpu=500m,memory=512Mi Warning: would violate PodSecurity "restricted:v1.24": ...output omitted... deployment.apps/frontend resource requirements updatedScale the
frontenddeployment to three pods.Scale the deployment.
[student@workstation ~]$ oc scale deployment/frontend --replicas 3 deployment.apps/frontend scaledWait for the deployment to scale up. You might have to rerun the command several times for the pods to report a
Runningstatus. The names of the pods on your system probably differ.[student@workstation ~]$ oc get pods NAME READY STATUS RESTARTS AGE frontend-86cdd7c7bf-8vrrs 1/1 Running 0 3m10s frontend-86cdd7c7bf-ds79w 1/1 Running 0 44s frontend-86cdd7c7bf-hpnwz 1/1 Running 0 44s quotesdb-66ff98b88c-fhwhs 1/1 Running 0 12m
Verify that the application responds to web requests.
Retrieve the URL of the application.
[student@workstation ~]$ oc get route NAME HOST/PORT PATH SERVICES ... frontend frontend-compreview-scale.apps.ocp4.example.com frontend ...Use the
curlcommand to test the application.[student@workstation ~]$ curl \ http://frontend-compreview-scale.apps.ocp4.example.com <html> <head> <title>Quotes</title> </head> <body> <h1>Quote List</h1> <ul> <li>1: When words fail, music speaks. - William Shakespeare </li> ...output omitted...
Evaluation
As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.
[student@workstation ~]$ lab grade compreview-scale
Finish
As the student user 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 compreview-scale
